package com.hsnn.medstgmini.pro.project.dao.impl;

import java.math.BigInteger;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.hsnn.medstgmini.Constants;
import com.hsnn.medstgmini.base.std.model.HospClassify;
import com.hsnn.medstgmini.base.std.model.HospInfo;
import com.hsnn.medstgmini.base.std.model.HospLevel;
import com.hsnn.medstgmini.dao.HibernateSqlUtil;
import com.hsnn.medstgmini.model.Status;
import com.hsnn.medstgmini.model.Whether;
import com.hsnn.medstgmini.pro.base.model.BaseGoods;
import com.hsnn.medstgmini.pro.project.dao.BidProjectDao;
import com.hsnn.medstgmini.pro.project.model.BidProjCompany;
import com.hsnn.medstgmini.pro.project.model.BidProjCompanyLog;
import com.hsnn.medstgmini.pro.project.model.BidProjdrugs;
import com.hsnn.medstgmini.pro.project.model.BidProjdrugsLog;
import com.hsnn.medstgmini.pro.project.model.BidProject;
import com.hsnn.medstgmini.pro.project.model.BidProjectDetails;
import com.hsnn.medstgmini.pro.project.model.BidProjectDetailsLog;
import com.hsnn.medstgmini.pro.project.model.BidProjhospital;
import com.hsnn.medstgmini.pro.project.model.BidProjhospitalLog;
import com.hsnn.medstgmini.pro.project.model.BidPubSettings;
import com.hsnn.medstgmini.pro.project.model.BidPubSettingsLog;
import com.hsnn.medstgmini.pro.project.model.form.BidProjectForm;
import com.hsnn.medstgmini.pro.project.model.form.BidPurProjDrugsForm;
import com.hsnn.medstgmini.sys.model.SysImportFileInfo;
import com.hsnn.medstgmini.sys.service.SysImportFileInfoManager;
import com.hsnn.medstgmini.util.AreaUtil;
import com.hsnn.medstgmini.util.ConstantsUtil;
import com.hsnn.medstgmini.util.DateUtil;
import com.hsnn.medstgmini.util.Pagination;
import com.hsnn.medstgmini.util.ParseDate;
import com.hsnn.medstgmini.util.PinYin;

@Repository("bidProjectDao")
public class BidProjectDaoImpl implements BidProjectDao {
	@Resource(name = "sessionFactory")
	private SessionFactory sessionFactory;
	@Autowired
	private HibernateSqlUtil dao;

	private Session getSession() {
		return sessionFactory.getCurrentSession();
	}

	/**
	 * 
	 * @category 分类采购项目查询
	 * @author 邱磊
	 * @date 2015年6月11日 上午10:33:20
	 * @param page
	 * @return
	 */
	public Pagination getDataList(Pagination page) {
		StringBuffer sql = new StringBuffer()
				.append("select a.proj_id as projId,a.name,a.proj_cat as projCat,a.status,DATE_FORMAT(a.create_datetime,'%Y-%m-%d %T') as createDatetime,DATE_FORMAT(bpd.price_quote_starttime,'%Y-%m-%d %H:%i:%S') as priceQuoteStarttime,DATE_FORMAT(bpd.price_quote_endtime,'%Y-%m-%d %H:%i:%S') as priceQuoteEndtime,DATE_FORMAT(bpd.proj_starttime,'%Y-%m-%d') as projStarttime,DATE_FORMAT(bpd.proj_endtime,'%Y-%m-%d') as projEndtime, ")
				.append("DATE_FORMAT(a.starttime,'%Y-%m-%d') as starttime,DATE_FORMAT(a.endtime,'%Y-%m-%d') as endtime,a.proj_intro as projIntro,DATE_FORMAT(bpd.price_quote_decode_starttime,'%Y-%m-%d %H:%i:%S') as priceQuoteDecodeStarttime,DATE_FORMAT(bpd.price_quote_decode_endtime,'%Y-%m-%d %H:%i:%S') as priceQuoteDecodeEndtime, ")
				.append("a.hospCount,a.drugCount,a.delCompCount,bpd.price_quote_password1 priceQuotePassword1 from view_bidproject a left join view_bidprojectstatus b on a.proj_id=b.proj_id left join bid_project_details bpd on bpd.proj_id =a.proj_id  where 1=1");
		Map<String, String> conditions = page.getConditions();
		Map<String, Object> params = new HashMap<String, Object>();
		if (null != conditions && conditions.size() > 0) {
			if (null != conditions.get("projId")
					&& !"".equals(conditions.get("projId").trim())) {
				sql.append(" and a.proj_id = :projId");
				params.put("projId", conditions.get("projId").trim());
			}
			if (null != conditions.get("status")
					&& !"".equals(conditions.get("status").trim())) {
				sql.append(" and a.status=:status");
				params.put("status", conditions.get("status").trim());
			}
		}
		String orderBy = page.getConditions().get("orderBy");
		if(StringUtils.isNotBlank(orderBy)){
			if(orderBy.equals(Constants.PRICE_QUOTE_STARTTIME)){//
				sql.append(" order by bpd.price_quote_starttime desc ");//招标密码页面排序
			}
			if(orderBy.equals(Constants.PROJ_STARTTIME)){
				sql.append(" order by bpd.proj_starttime desc ");//时间段查看页面排序
			}
		}else{
			sql.append(" order by a.starttime desc,a.name ");
		}
		List<?>  list = dao.getSqlMapList(sql.toString(), params);
		page.setRows(list);
		return page;
	}
	/**
	 * 
	 * @category 分类采购项目查询
	 * @author 邱磊
	 * @date 2015年6月11日 上午10:33:20
	 * @param page
	 * @return
	 */
	public Pagination getPurDataList(Pagination page) {
		StringBuffer sql = new StringBuffer()
				.append(" SELECT a.proj_id, a.proj_code, a.name, a.proj_cat, a.status, a.create_datetime, ")
				.append(" a.starttime, a.endtime, a.hospcount, a.drugcount, a.delCompCount ")
				.append(" from view_bidproject a where 1=1 ");
		Map<String, String> conditions = page.getConditions();
		Map<String, Object> params = new HashMap<String, Object>();
		if (null != conditions && conditions.size() > 0) {
			if (null != conditions.get("projCode")
					&& !"".equals(conditions.get("projCode").trim())) {
				sql.append(" and a.proj_code=:projCode");
				params.put("projCode", conditions.get("projCode").trim());
			}
			if (null != conditions.get("name")
					&& !"".equals(conditions.get("name").trim())) {
				sql.append(" and a.name like :name");
				params.put("name", "%" + conditions.get("name").trim() + "%");
			}
			if (null != conditions.get("status")
					&& !"".equals(conditions.get("status").trim())) {
				sql.append(" and a.status=:status");
				params.put("status", conditions.get("status").trim());
			}
		}
		sql.append(" order by a.status desc, a.create_datetime desc ");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}

	/**
	 *  
	 * @category 分类采购项目查询
	 * @author 邱磊
	 * @date 2015年6月11日 上午10:33:20
	 * @param page
	 * @return
	 */
	public Pagination getProjWithPlanList(Pagination page) {
		String name = page.getConditions().get("name");
		String status = page.getConditions().get("status");
		StringBuffer sql = new StringBuffer()
//<<<<<<< .mine
//		.append(" SELECT a.proj_id, a.proj_code, a.name, a.proj_cat, a.status, a.create_datetime, a.proj_intro, ")
//		.append(" a.starttime, a.endtime, a.remark, a.create_user, a.upd_datetime,a.upd_user, a.hospcount, a.drugcount, a.delCompCount ")
//		.append(" from view_bidproject a where exists (select 1 from bid_hospplan b where a.proj_id=b.proj_id) ");
//		Map<String, String> conditions = page.getConditions();
//		Map<String, Object> params = new HashMap<String, Object>();
//		if (null != conditions && conditions.size() > 0) {
//			if (null != conditions.get("projCode")
//					&& !"".equals(conditions.get("projCode").trim())) {
//				sql.append(" and a.proj_code=:projCode");
//				params.put("projCode", conditions.get("projCode").trim());
//			}
//			if (null != conditions.get("name")
//					&& !"".equals(conditions.get("name").trim())) {
//				sql.append(" and a.name like :name");
//				params.put("name", "%"+conditions.get("name").trim()+"%");
//			}
//			if (null != conditions.get("status")
//					&& !"".equals(conditions.get("status").trim())) {
//				sql.append(" and a.status=:status");
//				params.put("status", conditions.get("status").trim());
//			}
//=======
		.append("	SELECT a.proj_id projId,b.name projName,b.proj_code projCode, ")
		.append("	b.proj_cat projCat,b.status status, ")
		.append("	b.plan_start_datetime starttime, ")
		.append("	b.plan_end_datetime endtime ")
		.append("	FROM  bid_hospplan a  ")
		.append("	LEFT JOIN bid_project b ON b.proj_id = a.proj_id ")
		.append("	WHERE 1 = 1 ") ;
		Map<String,Object> params = new HashMap<String,Object>();
		if(StringUtils.isNotBlank(name)){
			sql.append(" and b.name like :name ");
			params.put("name", "%"+name+"%");
		}
		if(StringUtils.isNotBlank(status)){
			sql.append(" and b.status = :status ");
			params.put("status", status);
		}
		sql.append("	GROUP BY a.proj_id  order by b.starttime desc ");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	
	/**
	 * 
	 * @category 获取项目添加医疗机构信息
	 * @author 邱磊
	 * @date 2015年6月11日 上午11:52:57
	 * @param page
	 * @return
	 */
	public Pagination getAddHospDataList(Pagination page) {
		String projId = page.getConditions().get("projId");
		String hospName = page.getConditions().get("hospName");
		String hospClassify = page.getConditions().get("hospClassify");
		String hospCode = page.getConditions().get("hospCode");
		String areaId = page.getConditions().get("area3");
		String fatherArea = page.getConditions().get("area2");

		StringBuffer hql = new StringBuffer();
		hql.append(" select sh.hosp_id hospId,sh.hosp_code hospCode,sh.area_id areaId,sh.hosp_name hospName,");
		hql.append(" da.ar_fullname arfullname,sh.hosp_classify hospClassify,dh.hosp_type hospType,sh.hosp_level_id hospLevelId,");
		hql.append(" sh.org_code orgCode");
		hql.append(" from std_hospinfo sh ");
		hql.append(" left join ( select hosp_id from bid_projhospital where proj_id=:projId ) bph on sh.hosp_id =bph.hosp_id ");
		hql.append(" left join std_hospinfo_detail shd on sh.hosp_id = shd.hosp_id ");
		hql.append(" left join dic_area da on sh.area_id = da.area_id ");
		hql.append(" left join dic_hosptype dh on sh.hosp_type_id = dh.hosp_type_id ");
		hql.append(" where sh.status=1 and bph.hosp_id is null and sh.area_id like :province");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("province",  page.getConditions().get("province").substring(0, 2)+"%");
		params.put("projId", projId);
		if (StringUtils.isNotBlank(hospName)) {
			hql.append(" and (sh.hosp_spel_code like :hospSpelCode or sh.hosp_name like :hospName) ");
			params.put("hospSpelCode", "%"+hospName.trim().toUpperCase()+"%");
			params.put("hospName", "%"+hospName.trim()+"%");
		}
		if (StringUtils.isNotBlank(hospClassify)) {
			hql.append(" and sh.hosp_classify=:hospClassify");
			params.put("hospClassify", hospClassify);
		}
		if (StringUtils.isNotBlank(hospCode)) {
			hql.append(" and sh.hosp_code=:hospCode");
			params.put("hospCode", hospCode);
		}
		if (StringUtils.isNotBlank(areaId)) {
			hql.append(" and sh.area_id like :areaId");
			params.put("areaId", areaId);
		}
		else if (StringUtils.isNotBlank(fatherArea)){
			hql.append(" and da.father_id=:fatherId");
			params.put("fatherId", fatherArea);
			
		}
		hql.append(" order by sh.hosp_code");
		return dao.getSqlPageMapList(hql.toString(), params, page);
	}

	/**
	 * @category 将医疗机构类型类型由编码变为文字
	 * @author 韩守松
	 * @date 2015年7月8日
	 * @param @param list
	 * @param @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	protected List<Map> formatHospInfo(List<Map> list) {

		for (int i = 0; i < list.size(); i++) {
			Map map = list.get(i);
			String hospClassifyName = HospClassify.getName(Integer.valueOf(map
					.get("hospClassify") + ""));
			String hospLevelName = HospLevel.getName(map.get("hospLevelId")
					+ "");
			list.get(i).put("hospClassifyName", hospClassifyName);
			list.get(i).put("hospLevelName", hospLevelName);
		}
		return list;
	}

	/**
	 * @category 项目已添加药品启用停用
	 * @author 韩守松
	 * @date 2015年7月8日
	 * @param @return
	 */
	public boolean updateStatus(BidProjdrugs bidProjdrugs, Short status) {
		String sql = "update bid_projdrugs set status = :status where proj_drug_id = :projDrugId";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("status", status);
		params.put("projDrugId", bidProjdrugs.getProjDrugId());
		dao.executeSql(sql, params);
		return true;
	}

	/**
	 * @category 项目已添加药品批量启用停用
	 * @author 韩守松
	 * @date 2015年7月8日
	 * @param @return
	 */
	public boolean batchUpdateStatus(BidProjdrugs bidProjdrugs, Short status) {
		String userName = bidProjdrugs.getUpdUser();
		Timestamp updateTime = bidProjdrugs.getUpdDatetime();
		bidProjdrugs = (BidProjdrugs) this.getSession().get(BidProjdrugs.class,
				bidProjdrugs.getProjDrugId());
		bidProjdrugs.setStatus(status);
		bidProjdrugs.setUpdUser(userName);
		bidProjdrugs.setUpdDatetime(updateTime);
		this.getSession().saveOrUpdate(bidProjdrugs);
		this.getSession().flush();
		BidProjdrugsLog bidProjdrugsLog = new BidProjdrugsLog();
		BeanUtils.copyProperties(bidProjdrugs, bidProjdrugsLog);
		bidProjdrugsLog.setLogId(UUID.randomUUID().toString());
		this.getSession().save(bidProjdrugsLog);
		this.getSession().flush();
		return true;
	}

	public String addHost(String projId, String hospCode, String userId) {
		StringBuffer hql = new StringBuffer();
		hql.append(" insert into bid_projhospital select uuid(),a.proj_id,a.name,a.starttime,a.endtime,a.status,:hospCode,:status,now(),:updUser  from  bid_project a where a.proj_id =:projId");
		Query query1 = getSession().createSQLQuery(hql.toString());
		query1.setParameter("projId", projId)
		.setParameter("hospCode", hospCode)
		.setParameter("status", Whether.yes.getKey())
		.setParameter("updUser", userId);
		query1.executeUpdate();
		
		StringBuffer sql = new StringBuffer();
		sql.append(" insert into bid_projhospital_log  select uuid(),b.* from bid_projhospital b where b.proj_id=:projId ");
		Query query2 = getSession().createSQLQuery(sql.toString());
		query2.setParameter("projId", projId)
		.executeUpdate();
		return "success";
	}

	/**
	 * @category 根据ID获取项目信息
	 * @author 邱磊
	 * @date 2015-06-1
	 * @param bidProject
	 *            ：采购项目
	 * @return
	 */
	public BidProject getBidProjectById(String projId) {
		return (BidProject) dao.getUniquerResult(BidProject.class, projId);
	}
	/**
	 * 
	 *@category 根据项目ID获取项目详情
	 *@author 邱磊
	 *@date 2015年8月18日 上午10:48:11
	 *@param projId
	 *@return
	 */
	public BidProjectDetails getBidProjectDetailsById(String projId) {
		return (BidProjectDetails) dao.getUniquerResult(BidProjectDetails.class, projId);
	}

	/**
	 * @category 采购项目新增、修改
	 * @author 邱磊
	 * @date 2015-06-1
	 * @param bidProject
	 *            ：采购项目
	 * @return
	 */
	public void saveOrUpdate(BidProjectForm form) {
		if (null != form && !"".equals(form.getProjId())) {
			Date dt = new Date();
			BidProject data = getBidProjectById(form.getProjId());
//			BidProjectDetails dataDetails = getBidProjectDetailsById(form.getProjId());
			data.setProjCode(form.getProjCode());
			data.setName(form.getName());
			data.setProjIntro(form.getProjIntro());
			data.setStarttime(form.getStarttime()==null?null:ParseDate.fromShortFormat(form.getStarttime()));
			data.setEndtime(form.getEndtime()==null?null:ParseDate.fromShortFormat(form.getEndtime()));
			data.setProjCat(form.getProjCat());
			data.setRemark(form.getRemark());
			data.setUpdDatetime(dt);
			data.setUpdUser(form.getUpdUser());
			data.setStatus(1);
//			dataDetails.setProjStarttime(form.getProjStarttime()==null?null:ParseDate.fromShortFormat(form.getProjStarttime()));
//			dataDetails.setProjEndtime(form.getProjEndtime()==null?null:ParseDate.fromShortFormat(form.getProjEndtime()));
//			
//			dataDetails.setEntProAppStarttime(form.getEntProAppStarttime()==null?null:ParseDate.fromShortFormat(form.getEntProAppStarttime()));
//			dataDetails.setEntProAppEndtime(form.getEntProAppEndtime()==null?null:ParseDate.fromShortFormat(form.getEntProAppEndtime()));
//			dataDetails.setEntProAuditStarttime(form.getEntProAuditStarttime()==null?null:ParseDate.fromShortFormat(form.getEntProAuditStarttime()));
//			dataDetails.setEntProAuditEndtime(form.getEntProAuditEndtime()==null?null:ParseDate.fromShortFormat(form.getEntProAuditEndtime()));
//			dataDetails.setEntProAuditPubStarttime(form.getEntProAuditPubStarttime()==null?null:ParseDate.fromShortFormat(form.getEntProAuditPubStarttime()));
//			dataDetails.setEntProAuditPubEndtime(form.getEntProAuditPubEndtime()==null?null:ParseDate.fromShortFormat(form.getEntProAuditPubEndtime()));
//			dataDetails.setEntDrugAppStarttime(form.getEntDrugAppStarttime()==null?null:ParseDate.fromShortFormat(form.getEntDrugAppStarttime()));
//			dataDetails.setEntDrugAppEndtime(form.getEntDrugAppEndtime()==null?null:ParseDate.fromShortFormat(form.getEntDrugAppEndtime()));
//			dataDetails.setEntDrugAuditStarttime(form.getEntDrugAuditStarttime()==null?null:ParseDate.fromShortFormat(form.getEntDrugAuditStarttime()));
//			dataDetails.setEntDrugAuditEndtime(form.getEntDrugAuditEndtime()==null?null:ParseDate.fromShortFormat(form.getEntDrugAuditEndtime()));
//			dataDetails.setEntDrugAuditPubStarttime(form.getEntDrugAuditPubStarttime()==null?null:ParseDate.fromShortFormat(form.getEntDrugAuditPubStarttime()));
//			dataDetails.setEntDrugAuditPubEndtime(form.getEntDrugAuditPubEndtime()==null?null:ParseDate.fromShortFormat(form.getEntDrugAuditPubEndtime()));
//			dataDetails.setPriceQuoteSimuStarttime(form.getPriceQuoteSimuStarttime()==null?null:ParseDate.fromFullFormat(form.getPriceQuoteSimuStarttime()));
//			dataDetails.setPriceQuoteSimuEndtime(form.getPriceQuoteSimuEndtime()==null?null:ParseDate.fromFullFormat(form.getPriceQuoteSimuEndtime()));
//			dataDetails.setPriceQuoteStarttime(form.getPriceQuoteStarttime()==null?null:ParseDate.fromFullFormat(form.getPriceQuoteStarttime()));
//			dataDetails.setPriceQuoteEndtime(form.getPriceQuoteEndtime()==null?null:ParseDate.fromFullFormat(form.getPriceQuoteEndtime()));
//			dataDetails.setPriceQuoteDecodeStarttime(form.getPriceQuoteDecodeStarttime()==null?null:ParseDate.fromFullFormat(form.getPriceQuoteDecodeStarttime()));
//			dataDetails.setPriceQuoteDecodeEndtime(form.getPriceQuoteDecodeEndtime()==null?null:ParseDate.fromFullFormat(form.getPriceQuoteDecodeEndtime()));
//			dataDetails.setPriceQuotePassword1(form.getPriceQuotePassword1());
//			dataDetails.setPriceQuotePassword2(form.getPriceQuotePassword2());
//			dataDetails.setPriceQuotePassword3(form.getPriceQuotePassword3());
//			dataDetails.setPriceQuotePassword4(form.getPriceQuotePassword4());
//			dataDetails.setPriceQuotePassword5(form.getPriceQuotePassword5());
//			dataDetails.setPriceGradeStarttime(form.getPriceGradeStarttime()==null?null:ParseDate.fromShortFormat(form.getPriceGradeStarttime()));
//			dataDetails.setPriceGradeEndtime(form.getPriceGradeEndtime()==null?null:ParseDate.fromShortFormat(form.getPriceGradeEndtime()));
//			dataDetails.setSemiWinPubStarttime(form.getSemiWinPubStarttime()==null?null:ParseDate.fromShortFormat(form.getSemiWinPubStarttime()));
//			dataDetails.setSemiWinPubEndtime(form.getSemiWinPubEndtime()==null?null:ParseDate.fromShortFormat(form.getSemiWinPubEndtime()));
//			dataDetails.setAppealStarttime(form.getAppealStarttime()==null?null:ParseDate.fromShortFormat(form.getAppealStarttime()));
//			dataDetails.setAppealEndtime(form.getAppealEndtime()==null?null:ParseDate.fromShortFormat(form.getAppealEndtime()));
//			dataDetails.setWinPubStarttime(form.getWinPubStarttime()==null?null:ParseDate.fromShortFormat(form.getWinPubStarttime()));
//			dataDetails.setWinPubEndtime(form.getWinPubEndtime()==null?null:ParseDate.fromShortFormat(form.getWinPubEndtime()));
			dao.update(data);
		} else {
			String projId = UUID.randomUUID().toString();
			BidProject data = new BidProject();
			BidProjectDetails dataDetails = new BidProjectDetails();
			data.setProjId(projId);
			data.setProjCode(form.getProjCode());
			data.setName(form.getName());
			data.setProjIntro(form.getProjIntro());
			data.setStarttime(form.getStarttime()==null?null:ParseDate.fromShortFormat(form.getStarttime()));
			data.setEndtime(form.getEndtime()==null?null:ParseDate.fromShortFormat(form.getEndtime()));
			data.setProjCat(form.getProjCat());
			data.setRemark(form.getRemark());
			data.setCreateDatetime(new Date());
			data.setStatus(1);
			data.setCreateUser(form.getUpdUser());
			dataDetails.setProjId(projId);
//			dataDetails.setProjStarttime(form.getProjStarttime()==null?null:ParseDate.fromShortFormat(form.getProjStarttime()));
//			dataDetails.setProjEndtime(form.getProjEndtime()==null?null:ParseDate.fromShortFormat(form.getProjEndtime()));
//			dataDetails.setEntProAppStarttime(form.getEntProAppStarttime()==null?null:ParseDate.fromShortFormat(form.getEntProAppStarttime()));
//			dataDetails.setEntProAppEndtime(form.getEntProAppEndtime()==null?null:ParseDate.fromShortFormat(form.getEntProAppEndtime()));
//			dataDetails.setEntProAuditStarttime(form.getEntProAuditStarttime()==null?null:ParseDate.fromShortFormat(form.getEntProAuditStarttime()));
//			dataDetails.setEntProAuditEndtime(form.getEntProAuditEndtime()==null?null:ParseDate.fromShortFormat(form.getEntProAuditEndtime()));
//			dataDetails.setEntProAuditPubStarttime(form.getEntProAuditPubStarttime()==null?null:ParseDate.fromShortFormat(form.getEntProAuditPubStarttime()));
//			dataDetails.setEntProAuditPubEndtime(form.getEntProAuditPubEndtime()==null?null:ParseDate.fromShortFormat(form.getEntProAuditPubEndtime()));
//			dataDetails.setEntDrugAppStarttime(form.getEntDrugAppStarttime()==null?null:ParseDate.fromShortFormat(form.getEntDrugAppStarttime()));
//			dataDetails.setEntDrugAppEndtime(form.getEntDrugAppEndtime()==null?null:ParseDate.fromShortFormat(form.getEntDrugAppEndtime()));
//			dataDetails.setEntDrugAuditStarttime(form.getEntDrugAuditStarttime()==null?null:ParseDate.fromShortFormat(form.getEntDrugAuditStarttime()));
//			dataDetails.setEntDrugAuditEndtime(form.getEntDrugAuditEndtime()==null?null:ParseDate.fromShortFormat(form.getEntDrugAuditEndtime()));
//			dataDetails.setEntDrugAuditPubStarttime(form.getEntDrugAuditPubStarttime()==null?null:ParseDate.fromShortFormat(form.getEntDrugAuditPubStarttime()));
//			dataDetails.setEntDrugAuditPubEndtime(form.getEntDrugAuditPubEndtime()==null?null:ParseDate.fromShortFormat(form.getEntDrugAuditPubEndtime()));
//			dataDetails.setPriceQuoteSimuStarttime(form.getPriceQuoteSimuStarttime()==null?null:ParseDate.fromFullFormat(form.getPriceQuoteSimuStarttime()));
//			dataDetails.setPriceQuoteSimuEndtime(form.getPriceQuoteSimuEndtime()==null?null:ParseDate.fromFullFormat(form.getPriceQuoteSimuEndtime()));
//			dataDetails.setPriceQuoteStarttime(form.getPriceQuoteStarttime()==null?null:ParseDate.fromFullFormat(form.getPriceQuoteStarttime()));
//			dataDetails.setPriceQuoteEndtime(form.getPriceQuoteEndtime()==null?null:ParseDate.fromFullFormat(form.getPriceQuoteEndtime()));
//			dataDetails.setPriceQuoteDecodeStarttime(form.getPriceQuoteDecodeStarttime()==null?null:ParseDate.fromFullFormat(form.getPriceQuoteDecodeStarttime()));
//			dataDetails.setPriceQuoteDecodeEndtime(form.getPriceQuoteDecodeEndtime()==null?null:ParseDate.fromFullFormat(form.getPriceQuoteDecodeEndtime()));
//			dataDetails.setPriceQuotePassword1(form.getPriceQuotePassword1());
//			dataDetails.setPriceQuotePassword2(form.getPriceQuotePassword2());
//			dataDetails.setPriceQuotePassword3(form.getPriceQuotePassword3());
//			dataDetails.setPriceQuotePassword4(form.getPriceQuotePassword4());
//			dataDetails.setPriceQuotePassword5(form.getPriceQuotePassword5());
//			dataDetails.setPriceGradeStarttime(form.getPriceGradeStarttime()==null?null:ParseDate.fromShortFormat(form.getPriceGradeStarttime()));
//			dataDetails.setPriceGradeEndtime(form.getPriceGradeEndtime()==null?null:ParseDate.fromShortFormat(form.getPriceGradeEndtime()));
//			dataDetails.setSemiWinPubStarttime(form.getSemiWinPubStarttime()==null?null:ParseDate.fromShortFormat(form.getSemiWinPubStarttime()));
//			dataDetails.setSemiWinPubEndtime(form.getSemiWinPubEndtime()==null?null:ParseDate.fromShortFormat(form.getSemiWinPubEndtime()));
//			dataDetails.setAppealStarttime(form.getAppealStarttime()==null?null:ParseDate.fromShortFormat(form.getAppealStarttime()));
//			dataDetails.setAppealEndtime(form.getAppealEndtime()==null?null:ParseDate.fromShortFormat(form.getAppealEndtime()));
//			dataDetails.setWinPubStarttime(form.getWinPubStarttime()==null?null:ParseDate.fromShortFormat(form.getWinPubStarttime()));
//			dataDetails.setWinPubEndtime(form.getWinPubEndtime()==null?null:ParseDate.fromShortFormat(form.getWinPubEndtime()));
			dataDetails.setPasswordCount(form.getPasswordCount());
			dataDetails.setUpdDatetime(new Date());
			dataDetails.setUpdUser(form.getUpdUser());
			dao.add(data);
			dao.add(dataDetails);
			writeDetailLog(dataDetails);
		}
	}
	
	
	
	/**
	 * 
	 *@category 启用停用（批量）
	 *@author 邱磊
	 *@date 2015年8月18日 上午11:57:17
	 *@param list
	 *@param userId
	 */
	@Transactional
	public void batchSwitchStatus(List<BidProject> list, String userId){
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				BidProject form = list.get(i);
				BidProject data = getBidProjectById(form.getProjId());
				data.setStatus(form.getStatus());
				data.setUpdDatetime(new Date());
				data.setUpdUser(userId);
				dao.update(data);
			}
		}
	}
	/**
	 * 
	 *@category 写项目详情日志
	 *@author 邱磊
	 *@date 2015年8月18日 下午1:21:50
	 *@param data
	 */
	private void writeDetailLog(BidProjectDetails data){
		BidProjectDetailsLog log = new BidProjectDetailsLog();
		BeanUtils.copyProperties(data, log);
		log.setLogId(UUID.randomUUID().toString());
		dao.add(log);
	}
	
	/**
	 * 
	 *@category 获取项目详情
	 *@author 邱磊
	 *@date 2015年8月18日 下午1:34:15
	 *@param projId
	 *@return
	 */
	@SuppressWarnings("unchecked")
	public Map<String, Object> getDataDetail(String projId){
		StringBuffer sql = new StringBuffer()
		.append("select a.proj_id as projId,a.proj_code as projCode,a.name,a.proj_intro as projIntro,DATE_FORMAT(a.starttime,'%Y-%m-%d') as starttime,")
		.append("DATE_FORMAT(a.endtime,'%Y-%m-%d') as endtime,a.proj_cat as projCatId,c.dic_name as projCat,a.remark,a.status,")
		.append("DATE_FORMAT(a.create_datetime,'%Y-%m-%d %T') as createDatetime,d.name as createUser,DATE_FORMAT(a.upd_datetime,'%Y-%m-%d %T') as updDatetime,")
		.append("e.name as updUser,")
		.append("DATE_FORMAT(b.proj_starttime,'%Y-%m-%d') as projStarttime,DATE_FORMAT(b.proj_endtime,'%Y-%m-%d') as projEndtime,")
		.append("DATE_FORMAT(b.pro_submit_starttime,'%Y-%m-%d') as proSubmitStarttime,DATE_FORMAT(b.pro_submit_endtime,'%Y-%m-%d') as proSubmitEndtime,")
		.append("DATE_FORMAT(b.pro_audit_starttime,'%Y-%m-%d') as proAuditStarttime,DATE_FORMAT(b.pro_audit_endtime,'%Y-%m-%d') as proAuditEndtime,")
		.append("DATE_FORMAT(b.pro_audit_pub_starttime,'%Y-%m-%d') as proAuditPubStarttime,DATE_FORMAT(b.pro_audit_pub_endtime,'%Y-%m-%d') as proAuditPubEndtime,")
		.append("DATE_FORMAT(b.complain_starttime,'%Y-%m-%d') as complainStarttime,DATE_FORMAT(b.complain_endtime,'%Y-%m-%d') as complainEndtime,")
		.append("DATE_FORMAT(b.complain_pub_starttime,'%Y-%m-%d') as complainPubStarttime,DATE_FORMAT(b.complain_pub_endtime,'%Y-%m-%d') as complainPubEndtime,")
		.append("DATE_FORMAT(b.price_quote_simu_starttime,'%Y-%m-%d %T') as priceQuoteSimuStarttime,DATE_FORMAT(b.price_quote_simu_endtime,'%Y-%m-%d %T') as priceQuoteSimuEndtime,")
		.append("DATE_FORMAT(b.price_quote_starttime,'%Y-%m-%d %T') as priceQuoteStarttime,DATE_FORMAT(b.price_quote_endtime,'%Y-%m-%d %T') as priceQuoteEndtime,")
		.append("DATE_FORMAT(b.price_quote_decode_starttime,'%Y-%m-%d %T') as priceQuoteDecodeStarttime,DATE_FORMAT(b.price_quote_decode_endtime,'%Y-%m-%d %T') as priceQuoteDecodeEndtime,")
		.append("b.price_quote_password1 as priceQuotePassword1,b.price_quote_password2 as priceQuotePassword2,")
		.append("b.price_quote_password3 as priceQuotePassword3,b.price_quote_password4 as priceQuotePassword4,b.price_quote_password5 as priceQuotePassword5,")
		.append("DATE_FORMAT(b.price_grade_starttime,'%Y-%m-%d') as priceGradeStarttime,DATE_FORMAT(b.price_grade_endtime,'%Y-%m-%d') as priceGradeEndtime,")
		.append("DATE_FORMAT(b.appeal_starttime,'%Y-%m-%d') as appealStarttime,DATE_FORMAT(b.appeal_endtime,'%Y-%m-%d') as appealEndtime,")
		.append("DATE_FORMAT(b.semi_win_pub_starttime,'%Y-%m-%d') as semiWinPubStarttime,DATE_FORMAT(b.semi_win_pub_endtime,'%Y-%m-%d') as semiWinPubEndtime,")
		.append("DATE_FORMAT(b.win_pub_starttime,'%Y-%m-%d') as winPubStarttime,DATE_FORMAT(b.win_pub_endtime,'%Y-%m-%d') as winPubEndtime,")
		.append("b.password_count as passwordCount,b.cur_status as curStatus,b.is_cur_status_close as isCurStatusClose")
		.append(" from bid_project a")
		.append(" left join bid_project_details b on a.proj_id=b.proj_id")
		.append(" left join dic_sysdic c on a.proj_cat=c.dic_code and c.classify_code=:classifyCode")
		.append(" left join sys_user d on d.id=a.create_user")
		.append(" left join sys_user e on e.id=d.upd_user")
		.append(" where a.proj_id=:projId");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("classifyCode", Constants.PROJ_CAT);
		params.put("projId", projId);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), params);
		if (null != list && list.size() > 0){
			Map<String, Object> map = list.get(0);
			return map;
		}
		return null;
	}
	
	/**
	 * 
	 *@category 批量添加医疗机构
	 *@author 邱磊
	 *@date 2015年8月18日 下午3:26:53
	 *@param page
	 */
	@SuppressWarnings("unchecked")
	public void batchAddHosp(Pagination page) {
		List<HospInfo> list = (List<HospInfo>) page.getRows();
		if (null != list && list.size() > 0) {
			Date dt = new Date();
			String userId = page.getConditions().get("userId");
			String projId = page.getConditions().get("projId");
			for (int i = 0; i < list.size(); i++) {
				HospInfo hinfo = list.get(i);
				BidProjhospital ph= new BidProjhospital();
				ph.setProjHospId(UUID.randomUUID().toString());
				ph.setHospCode(hinfo.getHospCode());
				ph.setProjId(projId);
				ph.setStatus(Short.valueOf("1"));
				ph.setUpdDatetime(dt);
				ph.setUpdUser(userId);
				dao.add(ph);
				writeAddHospLog(ph);
			}
		}
	}
	/**
	 * 
	 *@category 写采购项目医疗机构日志
	 *@author 邱磊
	 *@date 2015年8月18日 下午3:58:03
	 *@param data
	 */
	private void writeAddHospLog(BidProjhospital data){
		BidProjhospitalLog log = new BidProjhospitalLog();
		BeanUtils.copyProperties(data, log);
		log.setLogId(UUID.randomUUID().toString());
		dao.add(log);
	}

	/**
	 * @category 未添加药品分页查询
	 * @author 单大伟
	 * @date 2015-06-12
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Pagination getUnBidProjectDrugList(Pagination page) {

		String projId = page.getConditions().get("projId");
		String drugCode = page.getConditions().get("drugCode");
		String drugName = page.getConditions().get("drugName");
		String compName = page.getConditions().get("drugComp");
		String drugAttr = page.getConditions().get("baseDrug");
		
		StringBuffer sbsql = new StringBuffer()
		.append("select a.prod_id as drugId,a.drug_code as drugCode,b.qualityspec_name as drugName,b.form_name as formName,")
		.append("b.spec_name as specName,a.factor as factor,a.unit_name as unit,a.material_name as materialName,a.comp_code as compCode,")
		.append("a.comp_name as compName,a.drug_attr as drugAttr from std_proddruginfo a")
		.append(" left join std_drugqualityspec b on a.qualityspec_id=b.qualityspec_id")
		.append(" where a.drug_code not in")
		.append(" (select c.drug_code from bid_projdrugs c where c.proj_id=:projId) and a.status = 1 and b.status = 1");
		
		
		//查询总数
		StringBuffer sbsqlCount = new StringBuffer()
		.append("select count(*) from std_proddruginfo a")
		.append(" left join std_drugqualityspec b on a.qualityspec_id=b.qualityspec_id")
		.append(" where a.drug_code not in (select c.drug_code from bid_projdrugs c where c.proj_id=:projId)  and a.status = 1 and b.status = 1");

		if (StringUtils.isNotEmpty(drugCode)) {
			sbsql.append(" and a.drug_code = :drugCode");
			sbsqlCount.append(" and a.drug_code =:drugCode ");
		}
		if (StringUtils.isNotEmpty(drugName)) {
			sbsql.append(" and (b.qualityspec_name like :drugName or b.qualityspec_name_spel like :drugNameSpel)");
			sbsqlCount.append(" and (b.qualityspec_name like :drugName or b.qualityspec_name_spel like :drugNameSpel)");
		}
		if (StringUtils.isNotEmpty(compName)) {
			sbsql.append(" AND a.comp_name LIKE :compName");
			sbsqlCount.append(" and a.comp_name like :compName ");
		}
		
		// TODO： 1， 2 定义成常量
		if (StringUtils.isNotBlank(drugAttr)) {
			if ("1".equals(drugAttr)) {
				sbsql.append(" and (a.drug_attr = '1' or a.drug_attr = '2') ");
				sbsqlCount.append(" and (a.drug_attr = '1' or a.drug_attr = '2') ");
			}
			if ("0".equals(drugAttr)) {
				sbsql.append(" and (a.drug_attr != '1' and a.drug_attr != '2' or a.drug_attr is null) ");
				sbsqlCount.append(" and (a.drug_attr != '1' and a.drug_attr != '2' or a.drug_attr is null) ");
			}
		}

		Query queryCount = this.getSession().createSQLQuery(sbsqlCount.toString());//查询总数
		Query query = this.getSession().createSQLQuery(sbsql.toString());

		query.setParameter("projId", projId);
		queryCount.setParameter("projId", projId);

		if (StringUtils.isNotEmpty(drugCode)) {
			query.setParameter("drugCode", drugCode);
			queryCount.setParameter("drugCode", drugCode);
		}
		if (StringUtils.isNotEmpty(drugName)) {
			query.setParameter("drugName", "%" + drugName + "%");
			queryCount.setParameter("drugName", "%" + drugName + "%");
			query.setParameter("drugNameSpel", "%" + drugName + "%");
			queryCount.setParameter("drugNameSpel", "%" + drugName + "%");
		}
		if (StringUtils.isNotEmpty(compName)) {
			query.setParameter("compName", "%" + compName + "%");
			queryCount.setParameter("compName", "%" + compName + "%");
		}

		Long count = ((BigInteger) (queryCount.uniqueResult())).longValue();

		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		query.setFirstResult((page.getPage() - 1) * page.getMaxResults());
		query.setMaxResults(page.getMaxResults());
		List<Map> records = query.list();

		page.setRecords(count);

		page.setTotal(new Long(count % page.getMaxResults() == 0 ? count
				/ page.getMaxResults() : count / page.getMaxResults() + 1)
				.intValue());
		page.setRows(records);
		return page;
	}

	/**
	 * @category 批量添加药品到项目
	 * @author 陈镜宇
	 * @date 2015-06-12
	 * @remark 邱磊 2015-11-15对方法进行修改
	 */
	public void batchSubmitDrugTOProj(List<BidPurProjDrugsForm> drugList, String userId) {
		for (BidPurProjDrugsForm sdi : drugList) {
			StringBuffer sql = new StringBuffer()
			.append("insert into bid_projdrugs")
			.append(" select UUID(),a.proj_id,a.name,a.starttime,a.endtime,a.status,")
			.append(" :drugCode,:coumpCode,1,SYSDATE(),:userId")
			.append(" from bid_project a ")
			.append(" where a.proj_id=:projId");
			Map<String, Object> params =  new HashMap<String, Object>();
			params.put("drugCode", sdi.getDrugCode());
			params.put("coumpCode", sdi.getCompCode());
			params.put("userId", userId);
			params.put("projId", sdi.getProjId());
			dao.executeSql(sql.toString(), params);
		}
	}

	/**
	 * @category 项目未添加配送企业查询数据列表
	 * 
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Pagination getUnBidProjectCompList(Pagination page) {

		String projId = page.getConditions().get("projId");
		String compCode = page.getConditions().get("compCode");
		String compName = page.getConditions().get("compName");
		String shortName = page.getConditions().get("shortName");

		StringBuffer hql = new StringBuffer();
		hql.append("select c.comp_id compId,c.comp_code compCode,c.comp_name compName,c.comp_short_name compShortName,cg.comp_group_name compGroupName");
		hql.append(" from std_compinfo c  ");
		hql.append(" left join std_compgroup cg on cg.comp_group_id = c.comp_group_id ");
		hql.append(" where c.comp_code not in ");
		hql.append(" (select pc.comp_code from bid_projcompany pc ");
		hql.append(" where  pc.proj_id = '");
		// TODO: projId 作为parameter传入
		hql.append(projId);
		hql.append("') and c.comp_type = 2 ");
		hql.append(" and c.status = 1 ");
		// 企业编码条件查询
		if (StringUtils.isNotEmpty(compCode)) {
			hql.append(" and c.comp_code = :compCode ");
		}
		// 企业名称条件查询
		if (StringUtils.isNotEmpty(compName)) {
			if (PinYin.isPinYin(compName)) {
				hql.append(" and c.comp_spel_code like :compName ");
			} else {
				hql.append(" and c.comp_name like :compName ");
			}
		}
		// 企业简称条件查询
		if (StringUtils.isNotEmpty(shortName)) {
			if (PinYin.isPinYin(shortName)) {
				hql.append(" and c.comp_short_spel_code like :shortName ");
			} else {
				hql.append(" and c.comp_short_name like :shortName ");
			}
		}
		hql.append(" order by c.comp_code ");

		Query query = this.getSession().createSQLQuery(hql.toString());
		// 企业编码条件查询
		if (StringUtils.isNotEmpty(compCode)) {
			query.setParameter("compCode", compCode);
		}
		// 企业名称条件查询
		if (StringUtils.isNotEmpty(compName)) {
			if (PinYin.isPinYin(compName)) {
				query.setParameter("compName", "%" + compName + "%");
			} else {
				query.setParameter("compName", "%" + compName + "%");
			}
		}
		// 企业简称条件查询
		if (StringUtils.isNotEmpty(shortName)) {
			if (PinYin.isPinYin(shortName)) {
				query.setParameter("shortName", "%" + shortName + "%");
			} else {
				query.setParameter("shortName", "%" + shortName + "%");
			}
		}
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		List<Map> list = query.list();
		if (list.size() > 0) {
			page.setRecords(list.size());
		} else {
			page.setRecords(0);
		}
		query.setFirstResult((page.getPage() - 1) * page.getMaxResults());
		query.setMaxResults(page.getMaxResults());
		list = query.list();
		if (list.size() > 0) {
			page.setRows(list);
		} else {
			page.setRows(new ArrayList<Map>());
		}
		return page;
	}

	public void batchSubmitCompTOProj(List<BidProjCompany> CompList,BidProject bp) {
		Session session = getSession();
		session.clear();
		StringBuffer sb = new StringBuffer().append(" insert into bid_projcompany values  ");
		for (BidProjCompany sdi : CompList) {
			sb.append(" ( uuid(),:projId,:projName,:projStarttime,:projEndtime,:projStatus,'"+sdi.getCompCode()+"',:auditStatus,:status,:updDatetime,'"+sdi.getUpdUser()+"'),"); 
		}
		Query query = session.createSQLQuery(sb.substring(0,sb.length()-1).toString());
		query.setParameter("projId", bp.getProjId())
		.setParameter("projName", bp.getName())
		.setParameter("projStarttime", bp.getStarttime())
		.setParameter("projEndtime", bp.getEndtime())
		.setParameter("projStatus", bp.getStatus())
		.setParameter("auditStatus", null)
		.setParameter("status",Whether.yes.getKey())
		.setParameter("updDatetime", new Date())
		.executeUpdate();
		
		Query queryLog= session.createSQLQuery("insert into bid_projcompany_log select uuid(),t.* FROM bid_projcompany t where t.proj_id=:projId");
		queryLog.setParameter("projId", bp.getProjId()).executeUpdate();
		
		session.flush();
		session.clear();
	}

	/**
	 * @category 项目已添加配送企业数据查询
	 * @author 韩守松
	 * @date 2015年7月9日
	 * @param @param page
	 * @param @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Pagination getAddedBidProjectCompsList(Pagination page) {
		String projId = page.getConditions().get("projId");
		String compCode = page.getConditions().get("compCode");
		String compName = page.getConditions().get("compName");
		String shortName = page.getConditions().get("shortName");

		StringBuffer hql = new StringBuffer();
		hql.append("select c.comp_id compId,c.comp_code compCode,c.comp_name compName,c.comp_short_name compShortName,");
		hql.append("cg.comp_group_name compGroupName,pc.status status,pc.proj_del_id projDelId");
		hql.append(" from std_compinfo c  ");
		hql.append(" left join bid_projcompany pc on c.comp_code = pc.comp_code ");
		hql.append(" left join std_compgroup cg on c.comp_group_id = cg.comp_group_id ");
		hql.append(" where pc.proj_id =:projId and c.status=1 ");

		// 企业编码条件查询
		if (StringUtils.isNotEmpty(compCode)) {
			hql.append(" and c.comp_code = :compCode ");
		}
		// 企业名称条件查询
		if (StringUtils.isNotEmpty(compName)) {
			if (PinYin.isPinYin(compName)) {
				hql.append(" and c.comp_spel_code like :compName ");
			} else {
				hql.append(" and c.comp_name like :compName ");
			}
		}
		// 企业简称条件查询
		if (StringUtils.isNotEmpty(shortName)) {
			if (PinYin.isPinYin(shortName)) {
				hql.append(" and c.comp_short_spel_code like :shortName ");
			} else {
				hql.append(" and c.comp_short_name like :shortName ");
			}
		}
		hql.append(" order by c.comp_code ");

		Query query = this.getSession().createSQLQuery(hql.toString());

		if (StringUtils.isNotEmpty(projId)) {
			query.setParameter("projId", projId);
		}

		// 企业编码条件查询
		if (StringUtils.isNotEmpty(compCode)) {
			query.setParameter("compCode", compCode);
		}
		// 企业名称条件查询
		if (StringUtils.isNotEmpty(compName)) {
			if (PinYin.isPinYin(compName)) {
				query.setParameter("compName", "%" + compName + "%");
			} else {
				query.setParameter("compName", "%" + compName + "%");
			}
		}
		// 企业简称条件查询
		if (StringUtils.isNotEmpty(shortName)) {
			if (PinYin.isPinYin(shortName)) {
				query.setParameter("shortName", "%" + shortName + "%");
			} else {
				query.setParameter("shortName", "%" + shortName + "%");
			}
		}
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		List<Map> list = query.list();
		if (list.size() > 0) {
			page.setRecords(list.size());
		} else {
			page.setRecords(0);
		}
		query.setFirstResult((page.getPage() - 1) * page.getMaxResults());
		query.setMaxResults(page.getMaxResults());
		list = query.list();
		list = formatStatus(list);
		if (list.size() > 0) {
			page.setRows(list);
		} else {
			page.setRows(new ArrayList<Map>());
		}
		return page;
	}

	/**
	 * @category 项目已添加配送企业启用停用
	 * @author 单大伟
	 * @date 2015年7月9日
	 * @param @param bidProjCompany
	 * @param @param status
	 * @param @return
	 */
	public boolean updateCompStatus(BidProjCompany bidProjCompany, Integer status) {
		
		StringBuffer hql = new StringBuffer("update bid_projcompany set status =:status, upd_user =:updUser, upd_datetime =:updDttm where proj_del_id =:projDelId");
		Query query = getSession().createSQLQuery(hql.toString());
		query.setInteger("status", status);
		query.setParameter("updUser", bidProjCompany.getUpdUser());
		query.setTimestamp("updDttm", bidProjCompany.getUpdDatetime());
		query.setParameter("projDelId", bidProjCompany.getProjDelId());
		query.executeUpdate();
		
		hql = new StringBuffer();
        hql.append(" insert into bid_projcompany_log (log_id, proj_del_id, proj_id, comp_code, status, upd_datetime, upd_user) ")
		   .append(" values(?, ?, ?, ?, ?, ?, ?) ");
		query = getSession().createSQLQuery(hql.toString());
		query.setParameter(0, UUID.randomUUID().toString());
		query.setParameter(1, bidProjCompany.getProjDelId());
		query.setParameter(2, bidProjCompany.getProjId());
		query.setParameter(3, bidProjCompany.getCompId());
		query.setInteger(4, status);
		query.setTimestamp(5, bidProjCompany.getUpdDatetime());
		query.setParameter(6, bidProjCompany.getUpdUser());
		query.executeUpdate();
		this.getSession().flush();
	
		return true;
	}

	/**
	 * @category 项目已添加配送企业批量启用停用
	 * @author 韩守松
	 * @date 2015年7月9日
	 * @param @param bidProjCompany
	 * @param @param status
	 * @param @return
	 */
	public boolean batchUpdateCompStatus(BidProjCompany bidProjCompany,
			Integer status) {
		String userName = bidProjCompany.getUpdUser();
		Date updateTime = bidProjCompany.getUpdDatetime();
		bidProjCompany = (BidProjCompany) this.getSession().get(BidProjCompany.class, bidProjCompany.getProjDelId());
		bidProjCompany.setStatus(status);
		bidProjCompany.setUpdUser(userName);
		bidProjCompany.setUpdDatetime(updateTime);
		this.getSession().saveOrUpdate(bidProjCompany);
		this.getSession().flush();
		BidProjCompanyLog bidProjCompanyLog = new BidProjCompanyLog();
		bidProjCompanyLog.setCompId(bidProjCompany.getCompId());
		bidProjCompanyLog.setProjDelId(bidProjCompany.getProjDelId());
		bidProjCompanyLog.setProjId(bidProjCompany.getProjId());
		bidProjCompanyLog.setStatus(bidProjCompany.getStatus());
		bidProjCompanyLog.setUpdDatetime(bidProjCompany.getUpdDatetime());
		bidProjCompanyLog.setUpdUser(bidProjCompany.getUpdUser());
		bidProjCompanyLog.setLogId(UUID.randomUUID().toString());
		this.getSession().save(bidProjCompanyLog);
		this.getSession().flush();
		return true;
	}

	/**
	 * @category 已添加药品分页查询
	 * @author 言科
	 * @date 2015-06-13
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Pagination getAddedBidProjectDrugList(Pagination page) {
		String projId = page.getConditions().get("projId");
		String drugCode = page.getConditions().get("drugCode");
		String drugName = page.getConditions().get("drugName");
		String drugComp = page.getConditions().get("compName");
		String drugAttr = page.getConditions().get("drugAttr");
		String status = page.getConditions().get("status");
		StringBuffer sbsql = new StringBuffer()
		.append(" select a.proj_drug_id projDrugId,a.drug_code drugCode,c.qualityspec_name drugName,")
		.append("c.form_name formName,c.spec_name specName,b.factor factor,b.unit_name unit,b.material_name materialName,  ")
		.append(" b.comp_code compCode,b.comp_name compName,b.drug_attr drugAttr,a.status status ")
		.append(" from bid_projdrugs a")
		.append(" left join std_proddruginfo b on a.drug_code=b.drug_code")
		.append(" left join std_drugqualityspec c on c.qualityspec_id=b.qualityspec_id")
		.append(" where a.proj_id= :projId ");
		
		StringBuffer sbsqlcount = new StringBuffer()
		.append("select count(*) ")
		.append("from bid_projdrugs a")
		.append(" left join std_proddruginfo b on a.drug_code=b.drug_code")
		.append(" left join std_drugqualityspec c on c.qualityspec_id=b.qualityspec_id")
		.append(" where a.proj_id= :projId ");
		
		if (StringUtils.isNotBlank(status)) {
			sbsql.append(" and a.status = :status");
			sbsqlcount.append(" and a.status = :status");
		}
		if (StringUtils.isNotBlank(drugCode)) {
			sbsql.append(" and a.drug_code =:drugCode ");
			sbsqlcount.append(" and a.drug_code =:drugCode ");
		}
		if (StringUtils.isNotBlank(drugName)) {
			sbsql.append(" and ( c.qualityspec_name like :drugName or c.qualityspec_name_spel like :drugNameSpel)");
			sbsqlcount.append(" and ( c.qualityspec_name like :drugName or c.qualityspec_name_spel like :drugNameSpel)");
		}
		if (StringUtils.isNotBlank(drugComp)) {
			sbsql.append(" and (b.comp_name like :compName or b.comp_name_spel like :compNameSpel)");
			sbsqlcount.append(" and (b.comp_name like :compName or b.comp_name_spel like :compNameSpel)");
		}
		if (StringUtils.isNotBlank(drugAttr)) {
			if ("1".equals(drugAttr)) {
				sbsql.append(" and (b.drug_attr = '1' or b.drug_attr = '2') ");
				sbsqlcount.append(" and (b.drug_attr = '1' or b.drug_attr = '2') ");
			}
			if ("0".equals(drugAttr)) {
				sbsql.append(" and (b.drug_attr != '1' and b.drug_attr != '2' or b.drug_attr is null) ");
				sbsqlcount.append(" and (b.drug_attr != '1' and b.drug_attr != '2' or b.drug_attr is null) ");
			}
		}
		sbsql.append(" order by b.drug_code desc ");

		Query query = this.getSession().createSQLQuery(sbsql.toString());
		Query countquery = this.getSession().createSQLQuery(sbsqlcount.toString());
		query.setParameter("projId", projId);
		countquery.setParameter("projId", projId);
		if (StringUtils.isNotBlank(drugCode)) {
			query.setParameter("drugCode", drugCode);
			countquery.setParameter("drugCode", drugCode);
		}
		if (StringUtils.isNotBlank(drugName)) {
			query.setParameter("drugName", "%" + drugName + "%");
			countquery.setParameter("drugName", "%" + drugName + "%");
			query.setParameter("drugNameSpel", "%" + drugName + "%");
			countquery.setParameter("drugNameSpel", "%" + drugName + "%");
		}
		if (StringUtils.isNotBlank(drugComp)) {
			query.setParameter("compName", "%" + drugComp + "%");
			countquery.setParameter("compName", "%" + drugComp + "%");
			query.setParameter("compNameSpel", "%" + drugComp + "%");
			countquery.setParameter("compNameSpel", "%" + drugComp + "%");
		}
		if (StringUtils.isNotBlank(status)) {
			query.setParameter("status", status);
			countquery.setParameter("status", status);
		}
		Long count = ((BigInteger) (countquery.uniqueResult())).longValue();
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		query.setFirstResult((page.getPage() - 1) * page.getMaxResults());
		query.setMaxResults(page.getMaxResults());
		List<Map> records = query.list();

		page.setRecords(count);

		page.setTotal(new Long(count % page.getMaxResults() == 0 ? count
				/ page.getMaxResults() : count / page.getMaxResults() + 1)
				.intValue());
		page.setRows(records);
		return page;
	}

	/**
	 * @category 引用状态枚举
	 * @author 韩守松
	 * @date 2015年7月8日
	 * @param @param list
	 * @param @return
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	protected List<Map> formatStatus(List<Map> list) {

		for (int i = 0; i < list.size(); i++) {
			Map map = list.get(i);
			String statusText = ConstantsUtil.stdStatus(map.get("status") + "");
			list.get(i).put("statusText", statusText);
		}
		return list;
	}

	/**
	 * 
	 *@category 获取已添加的医疗机构数据
	 *@author 邱磊
	 *@date 2015年8月18日 下午4:10:08
	 *@param page
	 *@return
	 */
	public Pagination getHaveAddHospsList(Pagination page) {
		StringBuffer sql = new StringBuffer()
		.append("select b.hosp_id as hospId,a.proj_hosp_id as projHospId,b.hosp_code as hospCode,b.hosp_name as hospName,c.area_name as areaName,")
		.append("d.dic_name as hospClassify,e.dic_name as hospLevel,b.org_code as orgCode,a.status from bid_projhospital a")
		.append(" inner join std_hospinfo b on a.hosp_id=b.hosp_id")
		.append(" left join dic_area c on c.area_id=b.area_id")
		.append(" left join dic_sysdic d on d.dic_code=b.hosp_classify and d.classify_code=:hospClassCode")
		.append(" left join dic_sysdic e on e.dic_code=b.hosp_level_id and e.classify_code=:levelClassCode")
		.append(" where a.proj_id=:projId ");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("hospClassCode", Constants.HOSP_CAT);
		params.put("levelClassCode", Constants.HOSP_LEVEL);
		params.put("projId", map.get("projId"));
		if (StringUtils.isNotBlank(map.get("hospCode"))){
			sql.append(" and b.hosp_code=:hospCode");
			params.put("hospCode", map.get("hospCode"));
		}
		if (StringUtils.isNotBlank(map.get("hospName"))){
			sql.append(" and (b.hosp_name like :hospName or b.hosp_spel_code like :hospSeplCode)");
			params.put("hospName", "%"+map.get("hospName").trim()+"%");
			params.put("hospSeplCode", "%"+map.get("hospName").trim().toUpperCase()+"%");
		}
		if (StringUtils.isNotBlank(map.get("area3"))){
			sql.append(" and b.area_id=:areaId");
			params.put("areaId", map.get("area3"));
		}
		else if (StringUtils.isNotBlank(map.get("area2"))){
			sql.append(" and c.father_id=:fatherId");
			params.put("fatherId", map.get("area2"));
		}
		if (StringUtils.isNotBlank(map.get("hospClassify"))){
			sql.append(" and b.hosp_classify=:hospClassify");
			params.put("hospClassify", map.get("hospClassify"));
		}
		if (StringUtils.isNotBlank(map.get("status"))){
			sql.append(" and a.status=:status");
			params.put("status", map.get("status"));
		}
		if (StringUtils.isNotBlank(map.get("hospLevel"))){
			sql.append(" and b.hosp_level_id=:hospLevel");
			params.put("hospLevel", map.get("hospLevel"));
		}
		sql.append(" order by b.hosp_code");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}

	public void batchSubmitHospTOProj(List<BidProjhospital> hospList) {

		Session session = getSession();
		session.clear();
		for (BidProjhospital sdi : hospList) {
			session.save(sdi);
		}
		session.flush();
		session.clear();
	}

	/**
	 * 
	 *@category 已添加医疗机构停用启用
	 *@author 邱磊
	 *@date 2015年8月18日 下午5:00:50
	 *@param list
	 *@param userId
	 *@return
	 */
	public void batchSwitchHospStatus(List<BidProjhospital> list,String userId) {
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				BidProjhospital form = list.get(i);
				BidProjhospital data = (BidProjhospital) dao.getUniquerResult(BidProjhospital.class, form.getProjHospId());
				if (null != data){
					data.setStatus(form.getStatus());
					dao.update(data);
					writeAddHospLog(data);
				}
			}
		}
	}
	
	/**
	 * 
	 *@category 获取添加药品数据
	 *@author 邱磊
	 *@date 2015年8月19日 上午9:31:56
	 *@param page
	 *@return
	 */
	public Pagination getAddDrugDataList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select a.drug_cata_id as drugCataId,a.qualityspec_class qualityspecClass,b.drugcatalog_code as drugcatalogCode,b.drugcatalog_name as drugcatalogName,")
		.append("b.attribute,c.qualityspec_code as qualityspecCode,c.qualityspec_name as qualityspecName,d.form_name as fromName,e.spec_name as specName")
		.append(" from bid_drugcatas a")
		.append(" left join std_drugcatalog b on b.drugcatalog_id=a.drugcatalog_id")
		.append(" left join std_drugqualityspec c on c.qualityspec_id=a.qualityspec_id")
		.append(" left join dic_drugform d on d.form_id=c.form")
		.append(" left join dic_drugspec e on e.spec_id=c.spec")
		.append(" where a.status=1 and b.status=1 and c.status=1");
		Map<String, String> map = page.getConditions();
		if (StringUtils.isNotBlank(map.get("qualityspecCode"))){
			sql.append(" and c.qualityspec_code=:qualityspecCode");
		}
		if (StringUtils.isNotBlank(map.get("qualityspecName"))){
			sql.append(" and (c.qualityspec_name like :qualityspecName or c.qualityspec_name_spel like :qualityspecName)");
			map.put("qualityspecName", "%"+map.get("qualityspecName").trim().toUpperCase()+"%");
		}
		if (StringUtils.isNotBlank(map.get("qualityspecClass"))){
			sql.append(" and a.qualityspec_class=:qualityspecClass");
		}
		
		sql.append(" order by c.qualityspec_code");
		return dao.getSqlPageMapList(sql.toString(),map, page);
	}
	
	/**
	 * @category 项目已添加医疗机构批量启用停用
	 * @author 单大伟
	 * @date 2015年7月8日
	 * @param @return
	 */
	public boolean batchUpdateHospStatus(BidProjhospital bidProjhospital,
			Short status) {
		String userName = bidProjhospital.getUpdUser();
		Date updateTime = bidProjhospital.getUpdDatetime();
		bidProjhospital = (BidProjhospital) this.getSession().get(
				BidProjhospital.class, bidProjhospital.getProjHospId());
		bidProjhospital.setStatus(status);
		bidProjhospital.setUpdUser(userName);
		bidProjhospital.setUpdDatetime(updateTime);
		this.getSession().saveOrUpdate(bidProjhospital);
		this.getSession().flush();

		StringBuffer hql = new StringBuffer();
		hql.append(
				" insert into bid_projhospital_log (log_id, proj_hosp_id, proj_id, hosp_code, status, upd_datetime, upd_user) ")
				.append(" values(?, ?, ?, ?, ?, ?, ?) ");
		Query query = getSession().createSQLQuery(hql.toString());
		query = getSession().createSQLQuery(hql.toString());
		query.setParameter(0, UUID.randomUUID().toString());
		query.setParameter(1, bidProjhospital.getProjHospId());
		query.setParameter(2, bidProjhospital.getProjId());
		query.setParameter(3, bidProjhospital.getHospCode());
		query.setShort(4, status);
		query.setTimestamp(5, bidProjhospital.getUpdDatetime());
		query.setParameter(6, bidProjhospital.getUpdUser());
		query.executeUpdate();

		return true;
	}

	/**
	 * 
	 * @category 查询所有已启用的采购项目列表
	 * @author 张俊
	 * @date 2015年6月13日
	 * @param Pagination
	 * @param bidProject
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<BidProject> getBidProjectList(Pagination page,
			BidProject bidProject) {

		Session session = sessionFactory.getCurrentSession();
		// 查询总记录数
		StringBuffer sb = new StringBuffer();

		sb.append("select count(*) from BidProject p where p.status = 1 ");

		if (bidProject != null) {
			if (StringUtils.isNotEmpty(bidProject.getProjCode())) {
				sb.append(" and p.projCode like :projCode ");
			}
			if (StringUtils.isNotEmpty(bidProject.getName())) {
				sb.append(" and p.name like :name ");
			}
		}
		sb.append(" order by p.createDatetime desc ");
		Query query = session.createQuery(sb.toString());
		if (bidProject != null) {
			if (StringUtils.isNotEmpty(bidProject.getProjCode())) {
				query.setString("projCode", "%"
						+ bidProject.getProjCode().trim() + "%");
			}
			if (StringUtils.isNotEmpty(bidProject.getName())) {
				query.setString("name", "%" + bidProject.getName().trim() + "%");
			}
		}
		Long total = (Long) query.uniqueResult();
		page.setRecords(total);

		// 查询分页数据
		sb.setLength(0);
		sb.append("select p from BidProject p where p.status = 1 ");
		// 添加搜索条件
		if (bidProject != null) {
			if (StringUtils.isNotEmpty(bidProject.getProjCode())) {
				sb.append(" and p.projCode like :projCode ");
			}
			if (StringUtils.isNotEmpty(bidProject.getName())) {
				sb.append(" and p.name like :name ");
			}
		}
		sb.append(" order by p.createDatetime desc ");
		query = session.createQuery(sb.toString());
		// 搜索条件赋值
		if (bidProject != null) {
			if (StringUtils.isNotEmpty(bidProject.getProjCode())) {
				query.setString("projCode", "%"
						+ bidProject.getProjCode().trim() + "%");
			}
			if (StringUtils.isNotEmpty(bidProject.getName())) {
				query.setString("name", "%" + bidProject.getName().trim() + "%");
			}
		}
		query.setFirstResult(page.getFirstResult());
		// query.setMaxResults(page.getCount());
		query.setMaxResults(page.getMaxResults());
		return query.list();

	}

	/**
	 * 
	 * @category 根据企业类型和id获取采购项目列表
	 * @author 陈镜宇
	 * @date 2015年6月18日
	 * @param compId
	 * @param compType
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<BidProject> getBidProjectListByCompId(String compId, String compType) {

		StringBuffer hql = new StringBuffer();
		hql.append("from BidProject bp where bp.status=1 and :now between starttime and bp.endtime ");
		if (compType.equals("2")) {// 生产企业
			hql.append(" and exists (select 1 from ViewGoods vg where vg.projId=bp.projId and vg.prodCompId='").append(compId).append("')");
		} else if (compType.equals("3")) {// 配送企业
			hql.append(" and exists (select 1 from BidProjCompany bpc where bpc.projId=bp.projId and bpc.compId='").append(compId).append("')");
		} else if (compType.equals("4")) {// 医疗机构
			hql.append(" and exists (select 1 from BidProjhospital bph where bph.projId=bp.projId and bph.hospId='").append(compId).append("')");
		}
		Query query = getSession().createQuery(hql.toString());
		query.setDate("now", new Date());

		List<BidProject> bpl = query.list();
		return bpl;
	}

	/**
	 * @category 获取采购项目下拉框
	 * @author 韩守松
	 * @date 2015年6月16日
	 * @param @param page
	 * @param @param bidProject
	 * @param @return
	 */
	@SuppressWarnings("unchecked")
	public List<BidProject> getBidProjectSelectList(Pagination page,
			BidProject bidProject) {
		StringBuffer hql = new StringBuffer();
		hql.append("from BidProject");
		Query query = this.getSession().createQuery(hql.toString());
		return query.list();
	}

	public void switchStatus(BidProject data) {
		BidProject info = (BidProject) getBidProjectById(data.getProjId());
		info.setStatus(data.getStatus());
		info.setUpdUser(data.getUpdUser());
		info.setUpdDatetime(new Date());
		dao.add(info);
	}
	public void switchPurStatus(BidProject data) {
		BidProject info = (BidProject) getBidProjectById(data.getProjId());
		info.setStatus(data.getStatus());
		info.setUpdUser(data.getUpdUser());
		info.setUpdDatetime(new Date());
		dao.add(info);
	}
	/**
	 * 
	 * @category 获取项目未添加医疗机构信息
	 * @author 邱磊
	 * @date 2015年6月11日 上午11:52:57
	 * @param page
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Pagination getHospList(Pagination page) {
		String projId = page.getConditions().get("projId");
		String hospName = page.getConditions().get("hospName");
		String hospClassify = page.getConditions().get("hospClassify");
		String hospCode = page.getConditions().get("hospCode");
		String areaId = page.getConditions().get("areaId");
		String sql = "select * from bid_project t where t.proj_id = :projId";
		Map<String, Object> params =  new HashMap<String, Object>();
		params.put("projId", projId);
		List<Map<String, Object>> plist = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		Map<String, Object> pmap = null;
		if (null != plist && plist.size() > 0){
			pmap = plist.get(0);
		}

		StringBuffer hql = new StringBuffer();
		hql.append(" select ");
		hql.append(" sh.hosp_id hospId,sh.hosp_code hospCode,sh.area_id areaId,sh.hosp_name hospName,");
		hql.append(" da.ar_fullname arfullname,sh.hosp_classify hospClassify,dh.hosp_type hospType,sh.hosp_level_id hospLevelId,");
		hql.append(" sh.org_code orgCode");
		hql.append(" from std_hospinfo sh ");
		hql.append(" left join dic_area da on sh.area_id = da.area_id ");
		hql.append(" left join dic_hosptype dh on sh.hosp_type_id = dh.hosp_type_id ");
		hql.append(" where  sh.status=1");
		if (StringUtils.isNotEmpty(projId)) {
			hql.append(" and sh.hosp_code not in (select b.hosp_code from bid_projhospital b where b.proj_id =:projId) ");
		}
		if (StringUtils.isNotEmpty(hospName)) {
			if (PinYin.isPinYin(hospName.trim())) {
				hql.append(" and sh.hosp_spel_code like :hospName ");
			} else {
				hql.append(" and sh.hosp_name like :hospName ");
			}
		}
//		if (StringUtils.isNotEmpty(hospClassify)) {
//			hql.append(" and sh.hosp_classify=:hospClassify");
//		}
		if (StringUtils.isNotEmpty(hospCode)) {
			hql.append(" and sh.hosp_code=:hospCode");
		}
		if (StringUtils.isNotEmpty(areaId)) {
			hql.append(" and sh.area_id like :areaId");
		}
		if (null != pmap && null != pmap.get("proj_range") && !"".equals(pmap.get("proj_range").toString()) && !"0".equals(pmap.get("proj_range").toString())){
			hql.append(" and sh.hosp_classify=:hospClassify");
		}
		hql.append(" and sh.status=1");
		hql.append(" order by sh.hosp_code");
		Query query = getSession().createSQLQuery(hql.toString());

		if (StringUtils.isNotEmpty(projId)) {
			query.setParameter("projId", projId);
		}
		if (StringUtils.isNotEmpty(hospName)) {
			query.setParameter("hospName", "%" + hospName + "%");
		}
		if (null != pmap && null != pmap.get("proj_range") && !"".equals(pmap.get("proj_range").toString()) && !"0".equals(pmap.get("proj_range").toString())) {

			query.setInteger("hospClassify", Integer.valueOf(pmap.get("proj_range").toString()));
		}
		if (StringUtils.isNotEmpty(hospCode)) {

			query.setParameter("hospCode", hospCode);
		}
		if (StringUtils.isNotEmpty(areaId)) {
			query.setParameter("areaId", areaId + "%");
		}
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		List<Map> list = query.list();

		if (list.size() > 0) {
			page.setRecords(list.size());
		} else {
			page.setRecords(0);
		}

		query.setFirstResult((page.getPage() - 1) * page.getMaxResults());
		query.setMaxResults(page.getMaxResults());
		list = query.list();
		list = formatHospInfo(list);
		if (list.size() > 0) {
			page.setRows(list);
		} else {
			page.setRows(new ArrayList<HospInfo>());
		}

		page.setTotal(new Long(
				page.getRecords() % page.getMaxResults() == 0 ? page
						.getRecords() / page.getMaxResults() : page
						.getRecords() / page.getMaxResults() + 1).intValue());
		return page;
	}
	public void batchAddPurHosp(List<BidProjhospital> list,BidProject bp) {
		if (null != list && list.size() > 0) {
			Session session= getSession();
			StringBuffer hql = new StringBuffer();
			hql.append(" insert into bid_projhospital values ");
			for (int i = 0; i < list.size(); i++) {
				BidProjhospital hinfo = list.get(i);
				hql.append(" ( uuid(),:projId,:name,:starttime,:endtime,:projStatus,'"+hinfo.getHospCode()+"',:status,:updDatetime,'"+hinfo.getUpdUser()+"' ),");
			}
			Query query1 = session.createSQLQuery(hql.substring(0,hql.length()-1).toString());
			query1.setParameter("projId", bp.getProjId())
				.setParameter("name", bp.getName())
				.setParameter("starttime",bp.getStarttime())
				.setParameter("endtime", bp.getEndtime())
				.setParameter("projStatus",bp.getStatus())
				.setParameter("status", Whether.yes.getKey() )
				.setParameter("updDatetime", new Date());
			query1.executeUpdate();
			session.flush();
			session.clear();
			
			Session session2= getSession();
			StringBuffer sql = new StringBuffer();
			sql.append(" insert into bid_projhospital_log  select uuid(),b.* from bid_projhospital b where b.proj_id=:projId ");
			Query query2 = session2.createSQLQuery(sql.toString());
			query2.setParameter("projId", bp.getProjId())
			.executeUpdate();
			session2.flush();
			session2.clear();
		}
		
	}
	@Override
	public String getProjRangeById(String projId) {
		Query query = getSession().createSQLQuery("select proj_range from bid_project where proj_id=:projId");
		query.setParameter("projId", projId);
		Object obj = query.uniqueResult();
		return  obj.toString();
	}
	/**
	 * @category 采购项目新增、修改
	 * @author 张俊
	 * @date 2015-06-1
	 * @param bidProject
	 *            ：采购项目
	 * @return
	 */
	public void saveOrUpdateBidProject(BidProject bidProject) {
		dao.update(bidProject);
	}

	public void batchAddHosp(List<HospInfo> list) {
		if (null != list && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				HospInfo hinfo = list.get(i);
				addHost(hinfo.getHospName(), hinfo.getHospCode(),
						hinfo.getUpdUser());
			}

		}
	}
	@Override
	public void addBidProjInfo(BidProject bidProject) {
		dao.add(bidProject);
	}
	@Value("#{sysProp['system.province']}")
    private String province;
	
	@SuppressWarnings("unchecked")
	@Override
	public void loadBidProjhospital(BidProject bidProject) {
		
		String areaId=AreaUtil.getAreaStartCode(province, null, null);
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT  sh.hosp_code from std_hospinfo sh JOIN dic_area da ON sh.area_id = da.area_id ")
		   .append("LEFT JOIN dic_sysdic C ON sh.hosp_classify = C.dic_code  where  C.classify_code = '113' and sh.status = 1 ");
		if(StringUtils.isNotBlank(areaId)){
			sql.append(" and da.area_id like :areaId");
		}
		if(StringUtils.isNotBlank(bidProject.getProjRange())){
			if(!("0".equals(bidProject.getProjRange()))){
				sql.append(" and sh.hosp_classify=:hospClassify");
			}
		}
		Query queryHosp = getSession().createSQLQuery(sql.toString());
		if(StringUtils.isNotBlank(areaId)){
			queryHosp.setParameter("areaId", areaId+"%");
		}
		if(StringUtils.isNotBlank(bidProject.getProjRange())){
			if(!("0".equals(bidProject.getProjRange()))){
				queryHosp.setParameter("hospClassify", bidProject.getProjRange());	
			}
		}
		List<String> hospCodes = queryHosp.list();
		Session session=null;
		SQLQuery query2=null;
		StringBuffer sqlHosp=null;
		if(hospCodes.size()>0){
			 sqlHosp = new StringBuffer()
			.append(" insert into bid_projhospital (proj_hosp_id,proj_id,proj_name,proj_starttime,proj_endtime,proj_status,hosp_code,status) values ");
			for( String hospCode : hospCodes){
				sqlHosp.append("(uuid(),:projId,:projName,:projStarttime,:projEndtime,:projStatus,'"+hospCode+"',:status),");
			}
			session =  getSession();
			query2 = session.createSQLQuery(sqlHosp.substring(0, sqlHosp.length()-1));
			query2.setParameter("projId", bidProject.getProjId())
			.setParameter("projName", bidProject.getName())
			.setParameter("projStarttime", bidProject.getPlanStartDatetime())
			.setParameter("projEndtime", bidProject.getPlanEndDatetime())
			.setParameter("projStatus",bidProject.getStatus())
			.setParameter("status",Whether.yes.getKey())
			.executeUpdate();
			session.flush();
			session.clear();
			writeBidProjhospitalLog(bidProject.getProjId());
		}
	}
	
	 private void writeBidProjhospitalLog(String projId){
		 StringBuffer sqlHospLog=new StringBuffer()
		 .append(" insert into bid_projhospital_log  select uuid(),bid_projhospital.* from bid_projhospital where proj_id =:projId");
		 Session session =  getSession();
		 SQLQuery query = session.createSQLQuery(sqlHospLog.toString());
		 query.setParameter("projId", projId)
		 .executeUpdate();
		 session.flush();
		 session.clear();
	 }
	/**
	 * 
		 * 
		 *@category 根据上传文件ID获取文件信息
		 *@author 邱磊
		 *@date 2015年11月10日 上午11:53:29
		 *@param 
		 *@return SysImportFileInfo
	 */
	public SysImportFileInfo getImportFileById(String id){
		Session session = sessionFactory.openSession();
		SysImportFileInfo data = (SysImportFileInfo) session.get(SysImportFileInfo.class, id);
		session.clear();
		session.close();
		return data;
	}
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getQualityspec(String drugName, String formName, String specName){
		Session session = sessionFactory.openSession();
		String sql = "select * from std_drugqualityspec a where a.qualityspec_name=:qName and a.form_name=:formName and a.spec_name=:specName";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("qName", drugName);
		params.put("formName", formName);
		params.put("specName", specName);
		Query query = session.createSQLQuery(sql).setCacheable(true);
		if (params != null) {
			Iterator<?> list = params.entrySet().iterator();
			while (list.hasNext()) {
				Map.Entry<String, ?> entry = (Map.Entry<String, ?>) list.next();
				query.setParameter((String) entry.getKey(), entry.getValue());
			}
		}
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		List<Map<String, Object>> list = query.list();
		session.clear();
		session.close();
		return list;
	}
	public List<Map<String, Object>> getProddruginfo(String qid, String factor , String unit, String material, String compName){
		Session session = sessionFactory.openSession();
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuffer sql = new StringBuffer()
		.append("select * from std_proddruginfo a")
		.append(" where a.qualityspec_id=:qid ");
		params.put("qid", qid);
		if (StringUtils.isNotBlank(factor)){
			sql.append(" and a.factor=:factor");
			params.put("factor", factor);
		}
		if (StringUtils.isNotBlank(unit)){
			sql.append(" and a.unit_name=:unit");
			params.put("unit", unit);
		}
		if (StringUtils.isNotBlank(material)){
			sql.append(" and a.material_name=:materialName");
			params.put("materialName", material);
		}
		if (StringUtils.isNotBlank(compName)){
			sql.append(" and a.comp_name=:compName");
			params.put("compName", compName);
		}
		Query query = session.createSQLQuery(sql.toString()).setCacheable(true);
		if (params != null) {
			Iterator<?> list = params.entrySet().iterator();
			while (list.hasNext()) {
				Map.Entry<String, ?> entry = (Map.Entry<String, ?>) list.next();
				query.setParameter((String) entry.getKey(), entry.getValue());
			}
		}
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		List<Map<String, Object>> list = query.list();
		session.clear();
		session.close();
		return list;
	}
	public void deleteByFileId(String fileId){
		Session session = sessionFactory.openSession();
		
		String sql = "DELETE from bid_projdrugs_import where file_id=:fileId";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("fileId", fileId);
		
		Query query = session.createSQLQuery(sql);
		if (params != null) {
			Iterator<?> list = params.entrySet().iterator();
			while (list.hasNext()) {
				Map.Entry<String, ?> entry = (Map.Entry<String, ?>) list.next();
				query.setParameter((String) entry.getKey(), entry.getValue());
			}
		}
		query.executeUpdate();
		session.clear();
		session.close();
	}
	@SuppressWarnings("unchecked")
	@Override
	public void loadBidProjcompany(BidProject bidProject) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT A.comp_code FROM std_compinfo A where  A.status = 1 and A.comp_type = 2");
		Query queryComp = getSession().createSQLQuery(sql.toString());
		List<String> compCodes = queryComp.list();
		if(compCodes.size()>0){
			StringBuffer sqlComp = new StringBuffer()
			.append(" insert into bid_projcompany (proj_del_id,proj_id,proj_name,proj_starttime,proj_endtime,proj_status,comp_code,status) values ");
			for( String compCode : compCodes){
				sqlComp.append("(uuid(),:projId,:projName,:projStarttime,:projEndtime,:projStatus,'"+compCode+"',:status),");
			}  
			Session session =  getSession();
			SQLQuery query2 = session.createSQLQuery(sqlComp.substring(0, sqlComp.length()-1));
			query2.setParameter("projId", bidProject.getProjId())
			.setParameter("projName", bidProject.getName())
			.setParameter("projStarttime", bidProject.getPlanStartDatetime())
			.setParameter("projEndtime", bidProject.getPlanEndDatetime())
			.setParameter("projStatus",bidProject.getStatus())
			.setParameter("status",Whether.yes.getKey())
			.executeUpdate();
			session.flush();
			session.clear();
		} 
		writeBidProjcompanyLog(bidProject.getProjId());
	}
	
	public void writeBidProjcompanyLog(String projId){
		StringBuffer sb= new StringBuffer()
		.append(" insert into bid_projcompany_log select uuid(),bid_projcompany.* from bid_projcompany where proj_id =:projId ");
		Session session =getSession();
		Query query =  session.createSQLQuery(sb.toString());
		query.setParameter("projId", projId)
		.executeUpdate();
		session.flush();
		session.clear();
	}
	

	/**
	 * @category 根据项目编号查询项目信息
	 * @author 韩守松
	 * @date 2015年7月13日
	 * @param @return
	 */
	@SuppressWarnings("unchecked")
	public List<BidProject> getProjectListByProjectCode(BidProject bidProject) {
		StringBuffer hql = new StringBuffer();
		if (StringUtils.isEmpty(bidProject.getProjId())) {
			hql.append("from BidProject bp where bp.projCode = :projCode ");
		} else {
			hql.append("from BidProject bp where bp.projCode = :projCode and bp.projId != :projId ");
		}

		Query query = this.getSession().createQuery(hql.toString());
		if (StringUtils.isNotEmpty(bidProject.getProjCode())) {
			query.setParameter("projCode", bidProject.getProjCode());
		}
		if (StringUtils.isNotEmpty(bidProject.getProjId())) {
			query.setParameter("projId", bidProject.getProjId());
		}
		List<BidProject> list = query.list();
		return list;
	}

	/**
	 * @category 根据项目名称查询项目信息
	 * @author 韩守松
	 * @date 2015年7月13日
	 * @param @return
	 */
	@SuppressWarnings("unchecked")
	public List<BidProject> getProjectListByProjectName(BidProject bidProject) {
		StringBuffer hql = new StringBuffer();
		if (StringUtils.isEmpty(bidProject.getProjId())) {
			hql.append("from BidProject bp where bp.name = :name ");
		} else {
			hql.append("from BidProject bp where bp.name = :name and bp.projId != :projId ");
		}
		Query query = this.getSession().createQuery(hql.toString());
		if (StringUtils.isNotEmpty(bidProject.getName())) {
			query.setParameter("name", bidProject.getName());
		}
		if (StringUtils.isNotEmpty(bidProject.getProjId())) {
			query.setParameter("projId", bidProject.getProjId());
		}
		List<BidProject> list = query.list();
		return list;
	}
	/**
	 * 
	 *@category 获取采购项目日志详情
	 *@author 邱磊
	 *@date 2015年8月19日 下午2:16:21
	 *@param projId
	 *@param updDatetime
	 *@return
	 */
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getDetailLog(String projId,String updDatetime){
		StringBuffer sql = new StringBuffer()
		.append("select a.proj_id as projId,a.proj_code as projCode,a.name,a.proj_intro as projIntro,DATE_FORMAT(a.starttime,'%Y-%m-%d') as starttime,")
		.append("DATE_FORMAT(a.endtime,'%Y-%m-%d') as endtime,a.proj_cat as projCatId,c.dic_name as projCat,a.remark,a.status,")
		.append("DATE_FORMAT(a.create_datetime,'%Y-%m-%d %T') as createDatetime,d.name as createUser,DATE_FORMAT(a.upd_datetime,'%Y-%m-%d %T') as updDatetime,")
		.append("e.name as updUser,DATE_FORMAT(b.proj_starttime,'%Y-%m-%d') as projStarttime,DATE_FORMAT(b.proj_endtime,'%Y-%m-%d') as projEndtime,")
		.append("DATE_FORMAT(b.ent_pro_app_starttime,'%Y-%m-%d') as entProAppStarttime,DATE_FORMAT(b.ent_pro_app_endtime,'%Y-%m-%d') as entProAppEndtime,")
		.append("DATE_FORMAT(b.ent_pro_audit_starttime,'%Y-%m-%d') as entProAuditStarttime,DATE_FORMAT(b.ent_pro_audit_endtime,'%Y-%m-%d') as entProAuditEndtime,")
		.append("DATE_FORMAT(b.ent_pro_audit_pub_starttime,'%Y-%m-%d') as entProAuditPubStarttime,DATE_FORMAT(b.ent_pro_audit_pub_endtime,'%Y-%m-%d') as entProAuditPubEndtime,")
		
		.append("DATE_FORMAT(b.ent_drug_app_starttime,'%Y-%m-%d') as entDrugAppStarttime,DATE_FORMAT(b.ent_drug_app_endtime,'%Y-%m-%d') as entDrugAppEndtime,")
		.append("DATE_FORMAT(b.ent_drug_audit_starttime,'%Y-%m-%d') as entDrugAuditStarttime,DATE_FORMAT(b.ent_drug_audit_endtime,'%Y-%m-%d') as entDrugAuditEndtime,")
		.append("DATE_FORMAT(b.ent_drug_audit_pub_starttime,'%Y-%m-%d') as entDrugAuditPubStarttime,DATE_FORMAT(b.ent_drug_audit_pub_endtime,'%Y-%m-%d') as entDrugAuditPubEndtime,")
		.append("DATE_FORMAT(b.price_quote_simu_starttime,'%Y-%m-%d %T') as priceQuoteSimuStarttime,DATE_FORMAT(b.price_quote_simu_endtime,'%Y-%m-%d %T') as priceQuoteSimuEndtime,")
		.append("DATE_FORMAT(b.price_quote_starttime,'%%Y-%m-%d %T') as priceQuoteStarttime,DATE_FORMAT(b.price_quote_endtime,'%%Y-%m-%d %T') as priceQuoteEndtime,")
		.append("DATE_FORMAT(b.price_quote_decode_starttime,'%%Y-%m-%d %T') as priceQuoteDecodeStarttime,DATE_FORMAT(b.price_quote_decode_endtime,'%%Y-%m-%d %T') as priceQuoteDecodeEndtime,")

		.append("b.price_quote_password1 as priceQuotePassword1,b.price_quote_password2 as priceQuotePassword2,")
		.append("b.price_quote_password3 as priceQuotePassword3,b.price_quote_password4 as priceQuotePassword4,b.price_quote_password5 as priceQuotePassword5,")
		.append("DATE_FORMAT(b.price_grade_starttime,'%%Y-%m-%d %T') as priceGradeStarttime,DATE_FORMAT(b.price_grade_endtime,'%%Y-%m-%d %T') as priceGradeEndtime,")
		.append("DATE_FORMAT(b.semi_win_pub_starttime,'%Y-%m-%d') as semiWinPubStarttime,")
		.append("DATE_FORMAT(b.semi_win_pub_endtime,'%Y-%m-%d') as semiWinPubEndtime,DATE_FORMAT(b.appeal_starttime,'%Y-%m-%d') as appealStarttime,")
		.append("DATE_FORMAT(b.appeal_endtime,'%Y-%m-%d') as appealEndtime,DATE_FORMAT(b.win_pub_starttime,'%Y-%m-%d') as winPubStarttime,")
		.append("DATE_FORMAT(b.win_pub_endtime,'%Y-%m-%d') as winPubEndtime,b.price_quote_password1 as priceQuotePassword1,b.price_quote_password2 as priceQuotePassword2,")
		.append("b.price_quote_password3 as priceQuotePassword3,b.price_quote_password4 as priceQuotePassword4,b.price_quote_password5 as priceQuotePassword5")
		.append("  from bid_project_details_log b")
		.append(" left join bid_project a on a.proj_id=b.proj_id")
		.append("  left join dic_sysdic c on a.proj_cat=c.dic_code and c.classify_code=:classifyCode")
		.append(" left join sys_user d on d.id=a.create_user")
		.append(" left join sys_user e on e.id=d.upd_user")
		.append(" where a.proj_id=:projId");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("classifyCode", Constants.PROJ_CAT);
		params.put("projId", projId);
		if (StringUtils.isNotBlank(updDatetime)){
			sql.append(" and b.upd_datetime <=:updDatetime");
			params.put("updDatetime", updDatetime);
		}
		sql.append(" order by b.upd_datetime desc");
		return (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), params);
	}
	/**
	 * 
	 *@category 根据项目ID获取项目日志上一个更新时间
	 *@author 邱磊
	 *@date 2015年8月19日 下午4:19:19
	 *@param projId
	 *@return
	 */
	@SuppressWarnings("unchecked")
	public String getDetailLogLastUpdtime(String projId,String updDatetime){
		String sql = "select DATE_FORMAT(t.upd_datetime,'%Y-%m-%d %T') updDatetime from bid_project_details_log t where t.proj_id=:projId and t.upd_datetime > :updDatetime order by t.upd_datetime asc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("projId", projId);
		params.put("updDatetime", updDatetime);
		List<Map<String, Object>> list = (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
		if (null != list && list.size() > 0){
			Map<String, Object> map = list.get(0);
			if (null != map.get("updDatetime")){
				return map.get("updDatetime").toString();
			}
		}
		return null;
	}
	/**
	 * 
	 *@category 获取设置密码信息（如果没有设置过则可以直接设置，如果设置过需要输原密码进行设置）
	 *@author 邱磊
	 *@date 2015年8月20日 下午5:09:03
	 *@param projId
	 *@return
	 */
	public BidProjectDetails getPasswordInfo(String projId){
		return (BidProjectDetails) dao.getUniquerResult(BidProjectDetails.class, projId);
	}
	/**
	 * 
	 *@category 初始设置报价密码
	 *@author 邱磊
	 *@date 2015年8月21日 上午10:53:41
	 *@param projId
	 *@param password
	 */
	public void setPassword(String projId,String[] password){
		BidProjectDetails data = (BidProjectDetails) dao.getUniquerResult(BidProjectDetails.class, projId);
		if (null != data){
			for (int i = 0; i < password.length; i++){
				if (1 == i+1){
					data.setPriceQuotePassword1(DigestUtils.md5Hex(password[i]));
				}
				else if (2 == i+1){
					data.setPriceQuotePassword2(DigestUtils.md5Hex(password[i]));
				}
				else if (3 == i+1){
					data.setPriceQuotePassword3(DigestUtils.md5Hex(password[i]));
				}
				else if (4 == i+1){
					data.setPriceQuotePassword4(DigestUtils.md5Hex(password[i]));
				}
				else if (5 == i+1){
					data.setPriceQuotePassword5(DigestUtils.md5Hex(password[i]));
				}
				
			}
		}
		dao.update(data);
	}
	
	/**
	 * 
	 *@category 修改报价密码
	 *@author 邱磊
	 *@date 2015年8月21日 上午11:18:34
	 *@param projId
	 *@param password
	 *@param newPassword
	 *@return
	 */
	public Pagination modifyPassword(Pagination page){
		String projId = page.getConditions().get("projId");
		Object[] obj = (Object[]) page.getForm();
		String[] password = (String[]) obj[0];
		String[] newPassword = (String[]) obj[2];
		BidProjectDetails data = (BidProjectDetails) dao.getUniquerResult(BidProjectDetails.class, projId);
		if (null != data){
			for (int i = 0; i < password.length; i++){
				if (1 == i+1){
					if (!DigestUtils.md5Hex(password[i]).equals(data.getPriceQuotePassword1())){
						page.setSuccess(false);
						page.setMsg("密码"+(i+1)+"错误！");
						return page;
					}
					data.setPriceQuotePassword1(DigestUtils.md5Hex(newPassword[i]));
				}
				else if (2 == i+1){
					if (!DigestUtils.md5Hex(password[i]).equals(data.getPriceQuotePassword2())){
						page.setSuccess(false);
						page.setMsg("密码"+(i+1)+"错误！");
						return page;
					}
					data.setPriceQuotePassword2(DigestUtils.md5Hex(newPassword[i]));
				}
				else if (3 == i+1){
					if (!DigestUtils.md5Hex(password[i]).equals(data.getPriceQuotePassword3())){
						page.setSuccess(false);
						page.setMsg("密码"+(i+1)+"错误！");
						return page;
					}
					data.setPriceQuotePassword3(DigestUtils.md5Hex(newPassword[i]));
				}
				else if (4 == i+1){
					if (!DigestUtils.md5Hex(password[i]).equals(data.getPriceQuotePassword4())){
						page.setSuccess(false);
						page.setMsg("密码"+(i+1)+"错误！");
						return page;
					}
					data.setPriceQuotePassword4(DigestUtils.md5Hex(newPassword[i]));
				}
				else if (5 == i+1){
					if (!DigestUtils.md5Hex(password[i]).equals(data.getPriceQuotePassword5())){
						page.setSuccess(false);
						page.setMsg("密码"+(i+1)+"错误！");
						return page;
					}
					data.setPriceQuotePassword5(DigestUtils.md5Hex(newPassword[i]));
				}
				dao.update(data);
			}
		} else {
			page.setSuccess(false);
			page.setMsg("修改密码失败！");
			return page;
		}
		page.setSuccess(true);
		return page;
	}
	/**
	 * 
	 *@category 设置项目招标各阶段时间
	 *@author 邱磊
	 *@date 2015年8月21日 下午3:03:13
	 *@param form
	 */
	public void setProjTime(BidProjectForm form){
		BidProjectDetails dataDetails = getBidProjectDetailsById(form.getProjId());
		dataDetails.setProjStarttime(form.getProj_starttime()==null?null:ParseDate.fromShortFormat(form.getProj_starttime()));
		dataDetails.setProjEndtime(form.getProj_endtime()==null?null:ParseDate.fromShortFormat(form.getProj_endtime()));
		dataDetails.setProAuditStarttime(StringUtils.isNotBlank(form.getPro_audit_endtime())?ParseDate.fromFullFormat(form.getPro_audit_starttime()+" 00:00:00"):null);
		dataDetails.setProAuditEndtime(StringUtils.isNotBlank(form.getPro_audit_endtime())?ParseDate.fromFullFormat(form.getPro_audit_endtime()+" 23:59:59"):null);
		dataDetails.setProAuditPubStarttime(StringUtils.isNotBlank(form.getPro_audit_pub_starttime())?ParseDate.fromFullFormat(form.getPro_audit_pub_starttime()+" 00:00:00"):null);
		dataDetails.setProAuditPubEndtime(StringUtils.isNotBlank(form.getPro_audit_pub_endtime())?ParseDate.fromFullFormat(form.getPro_audit_pub_endtime()+" 23:59:59"):null);
		dataDetails.setPriceQuoteSimuStarttime(StringUtils.isNotBlank(form.getPrice_quote_simu_starttime())?ParseDate.fromFullFormat(form.getPrice_quote_simu_starttime()):null);
		dataDetails.setPriceQuoteSimuEndtime(StringUtils.isNotBlank(form.getPrice_quote_simu_endtime())?ParseDate.fromFullFormat(form.getPrice_quote_simu_endtime()):null);
		dataDetails.setPriceQuoteStarttime(StringUtils.isNotBlank(form.getPrice_quote_starttime())?ParseDate.fromFullFormat(form.getPrice_quote_starttime()):null);
		dataDetails.setPriceQuoteEndtime(StringUtils.isNotBlank(form.getPrice_quote_endtime())?ParseDate.fromFullFormat(form.getPrice_quote_endtime()):null);
		dataDetails.setPriceQuoteDecodeStarttime(StringUtils.isNotBlank(form.getPrice_quote_decode_starttime())?ParseDate.fromFullFormat(form.getPrice_quote_decode_starttime()):null);
		dataDetails.setPriceQuoteDecodeEndtime(StringUtils.isNotBlank(form.getPrice_quote_decode_endtime())?ParseDate.fromFullFormat(form.getPrice_quote_decode_endtime()):null);
		dataDetails.setPriceGradeStarttime(StringUtils.isNotBlank(form.getPrice_grade_starttime())?ParseDate.fromFullFormat(form.getPrice_grade_starttime()+" 00:00:00"):null);
		dataDetails.setPriceGradeEndtime(StringUtils.isNotBlank(form.getPrice_grade_endtime())?ParseDate.fromFullFormat(form.getPrice_grade_endtime()+" 23:59:59"):null);
		dataDetails.setSemiWinPubStarttime(StringUtils.isNotBlank(form.getSemi_win_pub_starttime())?ParseDate.fromFullFormat(form.getSemi_win_pub_starttime()+" 00:00:00"):null);
		dataDetails.setSemiWinPubEndtime(StringUtils.isNotBlank(form.getSemi_win_pub_endtime())?ParseDate.fromFullFormat(form.getSemi_win_pub_endtime()+" 23:59:59"):null);
		dataDetails.setAppealStarttime(StringUtils.isNotBlank(form.getAppeal_starttime())?ParseDate.fromFullFormat(form.getAppeal_starttime()+" 00:00:00"):null);
		dataDetails.setAppealEndtime(StringUtils.isNotBlank(form.getAppeal_endtime())?ParseDate.fromFullFormat(form.getAppeal_endtime()+" 23:59:59"):null);
		dataDetails.setWinPubStarttime(StringUtils.isNotBlank(form.getWin_pub_starttime())?ParseDate.fromFullFormat(form.getWin_pub_starttime()+" 00:00:00"):null);
		dataDetails.setWinPubEndtime(StringUtils.isNotBlank(form.getWin_pub_endtime())?ParseDate.fromFullFormat(form.getWin_pub_endtime()+" 23:59:59"):null);
		if (null != form.getCurStatus() && 0 != form.getCurStatus().intValue()){
			dataDetails.setCurStatus(form.getCurStatus());
			dataDetails.setIsCurStatusClose(1);
		} else {
			dataDetails.setIsCurStatusClose(0);
		}
		dataDetails.setProSubmitStarttime(StringUtils.isNotBlank(form.getPro_submit_starttime())?ParseDate.fromFullFormat(form.getPro_submit_starttime()+" 00:00:00"):null);
		dataDetails.setProSubmitEndtime(StringUtils.isNotBlank(form.getPro_submit_endtime())?ParseDate.fromFullFormat(form.getPro_submit_endtime()+" 23:59:59"):null);
		dataDetails.setComplainStarttime(StringUtils.isNotBlank(form.getComplain_starttime())?ParseDate.fromFullFormat(form.getComplain_starttime()+" 00:00:00"):null);
		dataDetails.setComplainEndtime(StringUtils.isNotBlank(form.getComplain_endtime())?ParseDate.fromFullFormat(form.getComplain_endtime()+" 23:59:59"):null);
		dataDetails.setComplainPubStarttime(StringUtils.isNotBlank(form.getComplain_pub_starttime())?ParseDate.fromFullFormat(form.getComplain_pub_starttime()+" 00:00:00"):null);
		dataDetails.setComplainPubEndtime(StringUtils.isNotBlank(form.getComplain_pub_starttime())?ParseDate.fromFullFormat(form.getComplain_pub_endtime()+" 23:59:59"):null);
		dao.update(dataDetails);
		writeDetailLog(dataDetails);
	}
	/**
	 * 
	 *@category 获取药物目录列表数据
	 *@author 邱磊
	 *@date 2015年8月24日 下午3:21:29
	 *@param page
	 *@return
	 */
	public Pagination getImportDrugByCatalogDataList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select t.drugcatalog_id as drugcatalogId,t.drugcatalog_code as drugcatalogCode,t.drugcatalog_name as drugcatalogName,")
		.append(" DATE_FORMAT(t.start_time,'%Y-%m-%d') as startTime,DATE_FORMAT(t.end_time,'%Y-%m-%d') as endTime,t.attribute")
		.append(" ,(select count(a.drug_cata_id) from bid_drugcatas a  left join ( select qualityspec_id  from bid_qualityspec where proj_id=:projId) b on b.qualityspec_id=a.qualityspec_id where (a.drugcatalog_id=t.drugcatalog_id and b.qualityspec_id is  null  and a.status=1 ) )    AS count ")
		.append(" from std_drugcatalog t")
		.append(" where t.status=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		if (StringUtils.isNotBlank(map.get("drugcatalogCode"))){
			sql.append(" and t.drugcatalog_code=:drugcatalogCode");
			params.put("drugcatalogCode", map.get("drugcatalogCode"));
		}
		if (StringUtils.isNotBlank(map.get("drugcatalogName"))){
			sql.append(" and t.drugcatalog_name like :drugcatalogName");
			params.put("drugcatalogName", "%"+map.get("drugcatalogName").trim()+"%");
		}
		if (StringUtils.isNotBlank(map.get("attribute"))){
			sql.append(" and t.attribute = :attribute");
			params.put("attribute", map.get("attribute"));
		}
		if (StringUtils.isNotBlank(map.get("projId"))){
			params.put("projId", map.get("projId"));
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	/**
	 * 
	 *@category 按目录全部导入（已经存在的不忽略）
	 *@author 邱磊
	 *@date 2015年8月24日 下午4:11:11
	 *@param page
	 */
	public void importDrugByCatalog(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("insert into bid_qualityspec select UUID(),:projId,a.qualityspec_id,a.drugcatalog_id,null,null,1,SYSDATE(),:userId from bid_drugcatas a ")
		.append(" left join std_drugqualityspec c on a.qualityspec_id=c.qualityspec_id")
		.append(" where a.drugcatalog_id=:drugcatalogId")
		.append(" and not exists(select * from bid_qualityspec b where b.qualityspec_id=a.qualityspec_id and b.proj_id=:projId) and a.status=1 and c.status=1");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("projId", page.getConditions().get("projId"));
		params.put("userId", page.getConditions().get("userId"));
		params.put("drugcatalogId", page.getConditions().get("drugcatalogId"));
		dao.executeSql(sql.toString(), params);
	}
	
	/**
	 * 
	 *@category 获取按药物目录逐条导入数据列表（排除已加入的）
	 *@author 邱磊
	 *@date 2015年8月25日 上午10:36:53
	 *@return
	 */
	public Pagination getDrugByCatalogDataList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select a.qualityspec_id as qualityspecId,a.drugcatalog_id as drugcatalogId,c.qualityspec_code as qualityspecCode,")
		.append("c.qualityspec_name as qualityspecName,c.qualityspec_name_spel as qualityspecNameSpel,")
		.append(" c.qualityspec_name_eng as qualityspecNameEng,d.form_name as formName,e.spec_name as specName,")
		.append("f.dic_name as qualityspecClass,a.qualityspec_index as qualityspecIndex")
		.append("  from bid_drugcatas a ")
		.append(" left join std_drugqualityspec c on a.qualityspec_id=c.qualityspec_id")
		.append(" left join dic_drugform d on d.form_id=c.form")
		.append(" left join dic_drugspec e on e.spec_id=c.spec")
		.append(" left join dic_sysdic f on f.dic_code=a.qualityspec_class and f.classify_code=:classifyCode")
		.append(" where a.drugcatalog_id=:drugcatalogId")
		.append(" and not exists(select * from bid_qualityspec b where b.qualityspec_id=a.qualityspec_id and b.proj_id=:projId)")
		.append(" and a.status=1 and c.status=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("drugcatalogId", map.get("drugcatalogId"));
		params.put("projId", map.get("projId"));
		params.put("classifyCode", Constants.QUALITYSPEC_CLASS);
		if (StringUtils.isNotBlank(map.get("qualityspecCode"))){
			sql.append(" and c.qualityspec_code=:qualityspecCode");
			params.put("qualityspecCode", map.get("qualityspecCode"));
		}
		if (StringUtils.isNotBlank(map.get("qualityspecName"))){
			sql.append(" and (c.qualityspec_name like :qualityspecName or c.qualityspec_name_spel like :qualityspecNameSpel)");
			params.put("qualityspecName", "%"+map.get("qualityspecName").trim()+"%");
			params.put("qualityspecNameSpel", "%"+map.get("qualityspecName").trim().toUpperCase()+"%");
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	/**
	 * 
	 *@category 逐条导入药物目录药品
	 *@author 邱磊
	 *@date 2015年8月25日 下午1:35:15
	 *@param pagef
	 */
	@SuppressWarnings("unchecked")
	public void importDrugByCatalogDetail(Pagination page){
		List<BidProjectForm> list = (List<BidProjectForm>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				BidProjectForm form = list.get(i);
				StringBuffer sql = new StringBuffer()
				.append("insert into  bid_qualityspec(bid_projqualityspec_id,proj_id,qualityspec_id,drugcatas_id,submit_comp_count,in_bus_comp_count,status,upd_datetime,upd_user)")
				.append(" VALUES(UUID(),:projId,:qualityspecId,:drugcatasId,null,null,1,SYSDATE(),:updUser)");
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("projId", page.getConditions().get("projId"));
				params.put("qualityspecId", form.getQualityspecId());
				params.put("drugcatasId", form.getDrugcatasId());
				params.put("updUser", page.getConditions().get("userId"));
				dao.executeSql(sql.toString(), params);
			}
		}
	}
	/**
	 * 
	 *@category 按品规导入药品
	 *@author 邱磊
	 *@date 2015年8月25日 下午1:35:15
	 *@param page
	 */
	@SuppressWarnings("unchecked")
	public void importDrugqualityspec(Pagination page){
		List<BidProjectForm> list = (List<BidProjectForm>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i++){
				BidProjectForm form = list.get(i);
				StringBuffer sql = new StringBuffer()
				.append("insert into  bid_qualityspec(bid_projqualityspec_id,proj_id,qualityspec_id,drugcatas_id,submit_comp_count,in_bus_comp_count,status,upd_datetime,upd_user)")
				.append(" VALUES(UUID(),:projId,:qualityspecId,:drugcatalogId,null,null,1,SYSDATE(),:updUser)");
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("projId", page.getConditions().get("projId"));
				params.put("qualityspecId", form.getQualityspecId());
				params.put("drugcatalogId", form.getDrugcatalogId());
				params.put("updUser", page.getConditions().get("userId"));
				dao.executeSql(sql.toString(), params);
			}
		}
	}
	/**
	 * 
	 *@category 获取按品规导入列表
	 *@author 邱磊
	 *@date 2015年8月25日 下午2:20:13
	 *@param page
	 *@return
	 */
	public Pagination getDrugqualityspecDataList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("SELECT bdc.drug_cata_id drugCataId,a.qualityspec_id as qualityspecId,a.qualityspec_code as qualityspecCode,a.qualityspec_name as qualityspecName,")
		.append("b.form_name as formName,c.spec_name as specName,sdc.drugcatalog_code drugcatalogCode,sdc.drugcatalog_name drugcatalogName,sdc.drugcatalog_id drugcatalogId ")
		.append(" from bid_drugcatas bdc left join std_drugcatalog sdc on  sdc.drugcatalog_id = bdc.drugcatalog_id left join std_drugqualityspec a on a.qualityspec_id = bdc.qualityspec_id ")
		.append(" left join  ( select qualityspec_id,drugcatas_id  from bid_qualityspec where proj_id=:projId ) d  on  a.qualityspec_id = d.qualityspec_id and d.drugcatas_id = sdc.drugcatalog_id  ")
		.append(" left join dic_drugform b on b.form_id=a.form")
		.append(" left join dic_drugspec c on c.spec_id=a.spec")
		.append(" where bdc.status=1")
		.append(" and d.qualityspec_id is null and d.drugcatas_id is null ");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("projId", map.get("projId"));
		if (StringUtils.isNotBlank(map.get("qualityspecCode"))){
			sql.append(" and a.qualityspec_code=:qualityspecCode");
			params.put("qualityspecCode", map.get("qualityspecCode"));
		}
		if (StringUtils.isNotBlank(map.get("qualityspecName"))){
			sql.append(" and (a.qualityspec_name like :qualityspecName or a.qualityspec_name_spel like :qualityspecNameSpel)");
			params.put("qualityspecName", "%"+map.get("qualityspecName").trim()+"%");
			params.put("qualityspecNameSpel", "%"+map.get("qualityspecName").trim().toUpperCase()+"%");
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	/**
	 * 
	 *@category 获取已添加药品数据
	 *@author 邱磊
	 *@date 2015年8月25日 下午4:37:19
	 *@param page
	 *@return
	 */
	public Pagination getHaveAddDrugDataList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select a.bid_projqualityspec_id as bidProjqualityspecId,c.drugcatalog_code as drugcatalogCode,a.status,")
		.append("c.drugcatalog_name as drugcatalogName,c.attribute ,e.dic_name as qualityspecClass,b.qualityspec_index as qualityspecIndex,")
		.append("d.qualityspec_code as qualityspecCode,d.qualityspec_name as qualityspecName,f.form_name as formName,g.spec_name as specName from bid_qualityspec a")
		.append(" left join bid_drugcatas b on a.drugcatas_id=b.drugcatalog_id and b.qualityspec_id=a.qualityspec_id and b.status=1")
		.append(" left join std_drugcatalog c on b.drugcatalog_id=c.drugcatalog_id")
		.append(" left join std_drugqualityspec d on d.qualityspec_id=a.qualityspec_id")
		.append(" left join dic_sysdic e on e.dic_code=b.qualityspec_class and e.classify_code=:classifyCode")
		.append(" left join dic_drugform f on f.form_id=d.form")
		.append(" left join dic_drugspec g on g.spec_id=d.spec")
		.append(" where a.proj_id=:projId");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("projId", map.get("projId"));
		params.put("classifyCode", Constants.QUALITYSPEC_CLASS);
		if (StringUtils.isNotBlank(map.get("qualityspecCode"))){
			sql.append(" and d.qualityspec_code=:qualityspecCode");
			params.put("qualityspecCode", map.get("qualityspecCode"));
		}
		if (StringUtils.isNotBlank(map.get("qualityspecName"))){
			sql.append(" and (d.qualityspec_name like :qualityspecName or d.qualityspec_name_spel like :qualityspecNameSpel)");
			params.put("qualityspecName", "%"+map.get("qualityspecName").trim()+"%");
			params.put("qualityspecNameSpel", "%"+map.get("qualityspecName").trim().toUpperCase()+"%");
		}
		if (StringUtils.isNotBlank(map.get("drugcatalogName"))){
			sql.append(" and c.drugcatalog_name like :drugcatalogName");
			params.put("drugcatalogName", "%"+map.get("drugcatalogName").trim()+"%");
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	/**
	 * 
	 *@category 启用停用已添加的药品（批量）
	 *@author 邱磊
	 *@date 2015年8月25日 下午6:44:16
	 *@param page
	 */
	@SuppressWarnings("unchecked")
	public void batchSwitchDrugStatus(Pagination page){
		List<BidProjectForm> list = (List<BidProjectForm>) page.getRows();
		if (null != list && list.size() > 0){
			Map<String, Object> params = new HashMap<String, Object>();
			for (int i = 0; i < list.size(); i++){
				params.put("status", page.getConditions().get("status"));
				BidProjectForm form = list.get(i);
				String sql = "UPDATE bid_qualityspec set status=:status where bid_projqualityspec_id=:bidProjqualityspecId";
				params.put("bidProjqualityspecId", form.getBidProjqualityspecId());
				dao.executeSql(sql, params);
				sql = "insert into bid_qualityspec_log select UUID(),b.* from bid_qualityspec b where b.bid_projqualityspec_id=:bidProjqualityspecId";
				params.remove("status");
				dao.executeSql(sql, params);
			}
		}
	}
	/**
	 * 
	 *@category 关闭当前正在进行的阶断
	 *@author 邱磊
	 *@date 2015年8月25日 下午8:21:54
	 *@param point
	 */
	public void closePoint(String point,String projId){
		StringBuffer updSql = new StringBuffer()
		.append("update bid_project_details set cur_status= :point ");
		updSql.append(" where proj_id=:projId");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("point", point);
		params.put("projId", projId);
		dao.executeSql(updSql.toString(), params);
	}
	/**
	 * 
	 *@category 开启下一个节点
	 *@author 邱磊
	 *@date 2015年8月25日 下午8:21:54
	 *@param point
	 */
	public void openPoint(String point,String projId){
		StringBuffer updSql = new StringBuffer()
		.append("update bid_project_details set cur_status= :point ");
		updSql.append(" where proj_id=:projId");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("point", point);
		params.put("projId", projId);
		dao.executeSql(updSql.toString(), params);
	
	}
	/**
	 * 
	 *@category 获取项目中已申报资质的企业列表
	 *@author 邱磊
	 *@date 2015年8月27日 上午9:12:42
	 *@param page
	 *@return
	 */
	public Pagination getCompprofileCompDataList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select  DATE_FORMAT(h.complain_endtime,'%Y-%m-%d') complainEndtime,DATE_FORMAT(h.complain_starttime,'%Y-%m-%d') complainStarttime,DATE_FORMAT(h.pro_audit_starttime,'%Y-%m-%d') proAuditStarttime,DATE_FORMAT(h.pro_audit_endtime,'%Y-%m-%d') proAuditEndtime ,h.cur_status curStatus,h.is_cur_status_close isCurStatusClose,b.comp_id as compId,c.comp_code as compCode,c.comp_name as compName,d.area_name as areaName,a.audit_status as auditStatus,a.complain_status as complainStatus,")
		.append("c.org_code as orgCode,c.comp_type as compType,f.name as projName,g.dic_name as projCat,a.proj_id as projId,DATE_FORMAT(SYSDATE(),'%Y-%m-%d') as nowDate from bid_projcompprofile a ")
		.append(" left join std_compprofile b on b.compprofile_id=a.compprofile_id")
		.append(" left join std_compinfo c on c.comp_id=b.comp_id")
		.append(" left join dic_area d on d.area_id=c.area_id")
		.append(" left join dic_comptype e on e.comp_reg_id=c.comp_reg_id")
		.append(" left join bid_project f on f.proj_id=a.proj_id")
		.append(" left join dic_sysdic g on g.dic_code=f.proj_cat and g.classify_code=:projCatCode")
		.append("  join bid_project_details h on f.proj_id=h.proj_id")
		.append(" where a.status=1 and b.status=1 and c.status=1"); //企业的状态status=1表示有效
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("projCatCode", Constants.PROJ_CAT);
		if (StringUtils.isNotBlank(map.get("projId"))){
			sql.append(" and a.proj_id=:projId");
			params.put("projId", map.get("projId"));
		}
		if (StringUtils.isNotBlank(map.get("compName"))){
			sql.append(" and (c.comp_name like :compName or c.comp_spel_code like :compSpelCode)");
			params.put("compName", "%"+map.get("compName").trim()+"%");
			params.put("compSpelCode", "%"+map.get("compName").trim().toUpperCase()+"%");
		}
		if (StringUtils.isNotBlank(map.get("compType"))){
			sql.append(" and c.comp_type=:compType");
			params.put("compType", map.get("compType"));
		}
		sql.append(" group by b.comp_id,f.proj_code");
		sql.append(" order by h.proj_starttime desc ");
		dao.getSqlPageMapList(sql.toString(), params,page);
		return page;
	}
	/**
	 * 
	 *@category 获取企业资质详情
	 *@author 邱磊
	 *@date 2015年8月27日 上午10:31:26
	 *@param projId
	 *@param compId
	 *@return
	 */
	public Pagination getCompprofileDetail(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select b.proj_compprofile_id as projCompprofileId,a.compprofile_id as compprofileId,a.profile_code as profileCode,")
		.append("a.profile_name as profileName,DATE_FORMAT(a.profile_starttime,'%Y-%m-%d') as profileStarttime,")
		.append("DATE_FORMAT(a.profile_endtime,'%Y-%m-%d') as profileEndtime,a.profile_pic_addr as profilePicAddr,a.profile_pic_shortcut_addr as profilePicShortcutAddr")
		.append(",b.audit_status as auditStatus,b.complain_status as complainStatus,DATE_FORMAT(b.audit_datetime, '%Y-%m-%d') as auditDatetime,b.audit_remark  auditRemark ")
		.append(" from bid_projcompprofile b left join std_compprofile a on b.compprofile_id=a.compprofile_id")
		.append(" where a.status=1 and b.status=1 and a.comp_id=:compId and b.proj_id=:projId");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("compId", map.get("compId"));
		params.put("projId", map.get("projId"));
		if (StringUtils.isNotBlank(map.get("applyType"))){
			sql.append(" and b.apply_type=:applyType");
			params.put("applyType", map.get("applyType"));
		}
		if (StringUtils.isNotBlank(map.get("auditStatus"))){
			sql.append(" and b.audit_status=:auditStatus");
			params.put("auditStatus", map.get("auditStatus"));
		}
		if (StringUtils.isNotBlank(map.get("complainStatus"))){
			sql.append(" and b.complain_status=:complainStatus");
			params.put("complainStatus", map.get("complainStatus"));
		}
		return  dao.getSqlPageMapList(sql.toString(), params, page);
	}
	/**
	 * 
	 *@category 审核企业资质
	 *@author 邱磊
	 *@date 2015年8月27日 下午4:28:36
	 *@param page
	 */
	public void auditCompprofile(Pagination page){
		String sql = "UPDATE bid_projcompprofile set audit_datetime=SYSDATE(),audit_status=:auditStatus,audit_remark=:auditRemark,complain_status=3,upd_datetime=SYSDATE(),upd_user=:updUser where proj_compprofile_id=:projCompprofileId";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("auditStatus", page.getConditions().get("auditStatus"));
		params.put("auditRemark", page.getConditions().get("auditRemark"));
		params.put("projCompprofileId", page.getConditions().get("projCompprofileId"));
		params.put("updUser", page.getConditions().get("userId"));
		dao.executeSql(sql, params);
		String logsql = "insert into bid_projcompprofile_log select UUID(),a.* from bid_projcompprofile a where a.proj_compprofile_id=:projCompprofileId";
		params.remove("auditStatus");
		params.remove("auditRemark");
		params.remove("updUser");
		dao.executeSql(logsql, params);
	}
	/**
	 * 
	 *@category 澄清审核企业资质
	 *@author 邱磊
	 *@date 2015年8月27日 下午4:28:36
	 *@param page
	 */
	public void auditCompprofileAudit(Pagination page){
		String sql = "UPDATE bid_projcompprofile set audit_datetime=SYSDATE(),complain_status=:complainStatus,complain_remark=:complainRemark,upd_datetime=SYSDATE(),upd_user=:updUser where proj_compprofile_id=:projCompprofileId";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("complainStatus", page.getConditions().get("complainStatus"));
		params.put("complainRemark", page.getConditions().get("complainRemark"));
		params.put("projCompprofileId", page.getConditions().get("projCompprofileId"));
		params.put("updUser", page.getConditions().get("userId"));
		dao.executeSql(sql, params);
		String logsql = "insert into bid_projcompprofile_log select UUID(),a.* from bid_projcompprofile a where a.proj_compprofile_id=:projCompprofileId";
		params.remove("complainStatus");
		params.remove("complainRemark");
		params.remove("updUser");
		dao.executeSql(logsql, params);
	}
	/**
	 * 
	 *@category 获取申报药品的生产企业列表数据
	 *@author 邱磊
	 *@date 2015年8月28日 上午9:47:29
	 *@return
	 */
	public Pagination getDeclareDrugByCompDataList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select b.comp_id as compId,b.comp_code as compCode,b.comp_name as compName,a.proj_proddrug_id as projProddrugId,")
		.append(" b.org_code as orgCode,c.area_name as areaName,d.comp_reg_name as compRegName,")
		.append(" count(a.prod_id) as prodCout from bid_projproddrug a")
		.append(" left join std_proddruginfo pr on pr.prod_id=a.prod_id")
		.append(" left join std_compinfo b on pr.prod_comp_id=b.comp_id")
		.append(" left join dic_area c on c.area_id=b.area_id")
		.append(" left join dic_comptype d on d.comp_reg_id=b.comp_reg_id")
		.append(" where a.status=1 and a.proj_id=:projId and b.status=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("projId", map.get("projId"));
		if (StringUtils.isNotBlank(map.get("compCode"))){
			sql.append(" and b.comp_code=:compCode");
			params.put("compCode", map.get("compCode"));
		}
		if (StringUtils.isNotBlank(map.get("compName"))){
			sql.append(" and (b.comp_name like :compName or b.comp_spel_code like :compSpelCode)");
			params.put("compName", "%"+map.get("compName").trim()+"%");
			params.put("compSpelCode", "%"+map.get("compName").trim().toUpperCase()+"%");
		}
		if (StringUtils.isNotBlank(map.get("areaName"))){
			sql.append(" and b.area_id=:areaId");
			params.put("areaId", map.get("areaName"));
		}
		else if (StringUtils.isNotBlank(map.get("fatherArea"))){
			sql.append(" and c.father_id=:fatherId");
			params.put("fatherId", map.get("fatherArea"));
		}
		sql.append(" group by b.comp_id");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	/**
	 * 
	 *@category 获取企业申报的药品列表数据
	 *@author 邱磊
	 *@date 2015年8月28日 上午10:26:54
	 *@return
	 */
	public Pagination getCompDeclareDrugList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select a.proj_proddrug_id as projProddrugId,b.drug_code as drugCode,c.qualityspec_name as qualityspecName,")
		.append("d.form_name as formName,e.spec_name as specName,b.factor,f.packunit_name as unit,g.material_name as materialName")
		.append(" from bid_projproddrug a")
		.append(" left join std_proddruginfo b on a.prod_id=b.prod_id")
		.append(" left join std_drugqualityspec c on c.qualityspec_id=b.qualityspec_id")
		.append(" left join dic_drugform d on d.form_id=c.form")
		.append(" left join dic_drugspec e on e.spec_id=c.spec")
		.append(" left join dic_packunit f on f.packunit_id=b.unit")
		.append(" left join dic_drugmaterial g on g.material_id=b.material_id")
		.append(" where a.proj_id=:projId and a.status=1 and b.prod_comp_id=:compId");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("projId", map.get("projId"));
		params.put("compId", map.get("compId"));
		if (StringUtils.isNotBlank(map.get("drugCode"))){
			sql.append(" and b.drug_code=:drugCode");
			params.put("drugCode", map.get("drugCode"));
		}
		if (StringUtils.isNotBlank(map.get("drugName"))){
			sql.append(" and (c.qualityspec_name like :qualityspecName or c.qualityspec_name_spel like :qualityspecNameSpel)");
			params.put("qualityspecName", "%"+map.get("drugName").trim()+"%");
			params.put("qualityspecNameSpel", "%"+map.get("drugName").trim().toUpperCase()+"%");
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	/**
	 * 
	 *@category 获取药品资质详情
	 *@author 邱磊
	 *@date 2015年8月28日 下午1:58:27
	 *@param page
	 *@return
	 */
	public Pagination getDrugCompprofileDetail(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select a.bid_compdrugprofile_id as bidCompdrugprofileId,b.profile_code as profileCode,b.profile_name as profileName,")
		.append("DATE_FORMAT(b.profile_starttime,'%Y-%m-%d') as profileStarttime,DATE_FORMAT(b.profile_endtime,'%Y-%m-%d') as profileEndtime,")
		.append("b.profile_pic_addr as profilePicAddr,b.profile_pic_shortcut_addr as profilePicShortcutAddr,a.audit_status as auditStatus,")
		.append("a.audit_remark as auditRemark,DATE_FORMAT(a.audit_datetime,'%Y-%m-%d %T') as auditDatetime,a.complain_status as complainStatus,")
		.append("a.complain_remark as complainRemark,DATE_FORMAT(a.complain_datetime,'%Y-%m-%d %T') as complainDatetime,")
		.append("a.complain_audit_remark as complainAuditRemark,DATE_FORMAT(a.complain_audit_datetime,'%Y-%m-%d %T') as complainAuditDatetime from bid_compdrugprofile a")
		.append(" left join std_compdrugprofile b on b.compprofile_id=a.compdrugprofile_id")
		.append(" where a.proj_proddrug_id=:projProddrugId");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("projProddrugId", page.getConditions().get("projProddrugId"));
		if (StringUtils.isNotBlank(page.getConditions().get("profileCode"))){
			sql.append(" and b.profile_code=:profileCode");
			params.put("profileCode", page.getConditions().get("profileCode"));
		}
		if (StringUtils.isNotBlank(page.getConditions().get("profileName"))){
			sql.append(" and b.profile_name like :profileName");
			params.put("profileName", "%"+page.getConditions().get("profileName").trim()+"%");
		}
		if (StringUtils.isNotBlank(page.getConditions().get("auditStatus"))){
			sql.append(" and a.audit_status=:auditStatus");
			params.put("auditStatus", page.getConditions().get("auditStatus"));
		}
		if (StringUtils.isNotBlank(page.getConditions().get("complainStatus"))){
			sql.append(" and a.complain_status=:complainStatus");
			params.put("complainStatus", page.getConditions().get("complainStatus"));
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	/**
	 * 
	 *@category 审核药品资质
	 *@author 邱磊
	 *@date 2015年8月28日 下午2:40:58
	 *@param page
	 */
	public void auditDrugCompprofile(Pagination page){
		String sql = "UPDATE bid_compdrugprofile set audit_datetime=SYSDATE(),audit_status=:auditStatus,audit_remark=:auditRemark,upd_datetime=SYSDATE(),upd_user=:updUser where bid_compdrugprofile_id=:bidCompdrugprofileId";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("auditStatus", page.getConditions().get("auditStatus"));
		params.put("auditRemark", page.getConditions().get("auditRemark"));
		params.put("bidCompdrugprofileId", page.getConditions().get("bidCompdrugprofileId"));
		params.put("updUser", page.getConditions().get("userId"));
		dao.executeSql(sql, params);
		String logsql = "insert into bid_compdrugprofile_log select UUID(),a.* from bid_compdrugprofile a where a.bid_compdrugprofile_id=:bidCompdrugprofileId";
		params.remove("auditStatus");
		params.remove("auditRemark");
		params.remove("updUser");
		dao.executeSql(logsql, params);
	}
	/**
	 * 
	 *@category 审核药品资质澄清
	 *@author 邱磊
	 *@date 2015年8月28日 下午2:40:58
	 *@param page
	 */
	public void auditComplianDrugCompprofile(Pagination page){
		String sql = "UPDATE bid_compdrugprofile set complain_audit_datetime=SYSDATE(),complain_status=:complainStatus,complain_audit_remark=:complainAuditRemark,upd_datetime=SYSDATE(),upd_user=:updUser where bid_compdrugprofile_id=:bidCompdrugprofileId";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("complainStatus", page.getConditions().get("complainStatus"));
		params.put("complainAuditRemark", page.getConditions().get("complainAuditRemark"));
		params.put("bidCompdrugprofileId", page.getConditions().get("bidCompdrugprofileId"));
		params.put("updUser", page.getConditions().get("userId"));
		dao.executeSql(sql, params);
		String logsql = "insert into bid_compdrugprofile_log select UUID(),a.* from bid_compdrugprofile a where a.bid_compdrugprofile_id=:bidCompdrugprofileId";
		params.remove("complainStatus");
		params.remove("complainAuditRemark");
		params.remove("updUser");
		dao.executeSql(logsql, params);
	}
	/**
	 * 
	 *@category 获取按药品审核药品资质列表数据
	 *@author 邱磊
	 *@date 2015年8月29日 下午2:13:29
	 *@return
	 */
	public Pagination getAuditDrugCompprofileByDrugList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select a.proj_proddrug_id as projProddrugId,a.prod_id as prodId,b.drug_code as drugCode,c.qualityspec_code as qualityspecCode,")
		.append(" a.audit_status as auditStatus,a.complain_status as complainStatus,")
		.append(" c.qualityspec_name as qualityspecName,d.form_name as formName,e.spec_name as specName,f.comp_code as compCode,f.comp_name as compName")
		.append(" from bid_projproddrug a")
		.append(" left join std_proddruginfo b on a.prod_id=b.prod_id")
		.append(" left join std_drugqualityspec c on c.qualityspec_id=b.qualityspec_id")
		.append(" left join dic_drugform d on d.form_id=c.form")
		.append(" left join dic_drugspec e on e.spec_id")
		.append(" left join std_compinfo f on f.comp_id=b.prod_comp_id")
		.append(" where proj_id=:projId");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("projId", map.get("projId"));
		if (StringUtils.isNotBlank(map.get("drugCode"))){
			sql.append(" and b.drug_code=:drugCode");
			params.put("drugCode", map.get("drugCode"));
		}
		if (StringUtils.isNotBlank(map.get("qualityspecName"))){
			sql.append(" and (c.qualityspec_name like :qualityspecName or c.qualityspec_name_spel like :qualityspecNameSpel)");
			params.put("qualityspecName", "%"+map.get("qualityspecName").trim()+"%");
			params.put("qualityspecNameSpel", "%"+map.get("qualityspecName").trim().toUpperCase()+"%");
		}
		if (StringUtils.isNotBlank(map.get("compCode"))){
			sql.append(" and f.comp_code=:compCode");
			params.put("compCode", map.get("compCode"));
		}
		if (StringUtils.isNotBlank(map.get("compName"))){
			sql.append(" and (f.comp_name like :compName or f.comp_spel_code like :compSpelCode)");
			params.put("compName", "%"+map.get("compName").trim()+"%");
			params.put("compSpelCode", "%"+map.get("compName").trim().toUpperCase()+"%");
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	/**
	 * 
	 *@category 审核申报药品
	 *@author 邱磊
	 *@date 2015年8月31日 上午11:37:09
	 *@param page
	 */
	@SuppressWarnings("unchecked")
	public void auditDrug(Pagination page){
		List<BidProjectForm> list = (List<BidProjectForm>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i ++){
				BidProjectForm form = list.get(i);
				StringBuffer uSql = new StringBuffer()
				.append("update bid_projproddrug set audit_status=:auditStatus,audit_remark=:auditRemark,audit_datetime=SYSDATE(),")
				.append("upd_user=:updUser,upd_datetime=SYSDATE()")
				.append(" where proj_proddrug_id=:projProddrugId");
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("auditStatus", page.getConditions().get("auditStatus"));
				params.put("auditRemark", page.getConditions().get("auditRemark"));
				params.put("updUser", page.getConditions().get("updUser"));
				params.put("projProddrugId", form.getProjProddrugId());
				dao.executeSql(uSql.toString(), params);
				StringBuffer logsql = new StringBuffer()
				.append("insert into bid_projproddrug_log")
				.append(" select UUID(),a.* from bid_projproddrug a where a.proj_proddrug_id=:projProddrugId");
				params.remove("auditStatus");
				params.remove("auditRemark");
				params.remove("updUser");
				dao.executeSql(logsql.toString(), params);
			}
			
		}
	}
	/**
	 * 
	 *@category 澄清审核申报药品
	 *@author 邱磊
	 *@date 2015年8月31日 上午11:37:09
	 *@param page
	 */
	@SuppressWarnings("unchecked")
	public void auditComplainDrug(Pagination page){
		List<BidProjectForm> list = (List<BidProjectForm>) page.getRows();
		if (null != list && list.size() > 0){
			for (int i = 0; i < list.size(); i ++){
				BidProjectForm form = list.get(i);
				StringBuffer uSql = new StringBuffer()
				.append("update bid_projproddrug set complain_status=:complainStatus,complain_audit_status=:complainAuditRemark,audit_datetime=SYSDATE(),")
				.append("upd_user=:updUser,upd_datetime=SYSDATE()")
				.append(" where proj_proddrug_id=:projProddrugId");
				Map<String, Object> params = new HashMap<String, Object>();
				params.put("complainStatus", page.getConditions().get("complainStatus"));
				params.put("complainAuditRemark", page.getConditions().get("complainAuditRemark"));
				params.put("projProddrugId", form.getProjProddrugId());
				params.put("updUser", page.getConditions().get("updUser"));
				dao.executeSql(uSql.toString(), params);
				StringBuffer logsql = new StringBuffer()
				.append("insert into bid_projproddrug_log")
				.append(" select UUID(),a.* from bid_projproddrug a where a.proj_proddrug_id=:projProddrugId");
				params.remove("complainStatus");
				params.remove("complainAuditRemark");
				params.remove("updUser");
				dao.executeSql(logsql.toString(), params);
			}
			
		}
	}
	/**
	 * 
	 *@category 获取公示详情
	 *@author 邱磊
	 *@date 2015年8月31日 下午5:34:11
	 *@return
	 */
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getPubSettingDetail(String projId){
		StringBuffer sql = new StringBuffer()
		.append("select a.bid_pub_settings_id as bidPubSettingsId,a.script_name as scriptName,a.script_file as scriptFile,a.status")
		.append(" from bid_pub_settings a ")
		.append(" where a.proj_id=:projId");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("projId", projId);
		return (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), params);
	}
	/**
	 * 
	 *@category 新增设置
	 *@author 邱磊
	 *@date 2015年8月31日 下午6:37:24
	 *@param page
	 */
	public void addSetting(BidPubSettings data){
		data.setBidPubSettingsId(UUID.randomUUID().toString());
		data.setScriptSubmitDatetime( DateUtil.getTimeStamp());
		data.setStatus(0);
		data.setUpdDatetime( DateUtil.getTimeStamp());
		writeLog(data);
	}
	/**
	 * 
	 *@category 写项目公示日志
	 *@author 邱磊
	 *@date 2015年8月31日 下午7:02:06
	 *@param data
	 */
	private void writeLog(BidPubSettings data){
		BidPubSettingsLog log = new BidPubSettingsLog();
		BeanUtils.copyProperties(data, log);
		log.setLogId(UUID.randomUUID().toString());
	}
	/**
	 * 
	 *@category 获取项目下拉列表
	 *@author 邱磊
	 *@date 2015年9月2日 上午10:15:44
	 *@return
	 */
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> getProjList(){
		String sql = "SELECT t.proj_id as projId,t.name from bid_project t where t.status=1";
		return (List<Map<String, Object>>) dao.getSqlMapList(sql, null);
	}
	/**
	 * 
	 *@category 获取生产企业已申报的药品
	 *@author 邱磊
	 *@date 2015年9月2日 下午1:58:30
	 *@param page
	 *@return
	 */
	public Pagination getDeclareDrugDataList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select a.proj_proddrug_id as projProddrugId,b.name,d.prod_comp_id as compId,f.comp_code as compCode,f.comp_name as compName")
		.append(",f.org_code as orgCode,g.ar_fullname as areaName,d.drug_code as drugCode,e.qualityspec_name as qualityspecName,h.form_name as formName,i.spec_name as specName")
		.append(",d.factor,j.packunit_name as unit,k.material_name as materialName,a.audit_status as auditStatus,a.complain_status as complainStatus")
		.append(",b.proj_cat as projCat, b.proj_code as projCode, b.proj_id as projId")
		.append(" from bid_projproddrug a")
		.append(" left join bid_project b on a.proj_id=b.proj_id")
		.append(" left join dic_sysdic c on c.dic_code=b.proj_cat and c.classify_code=:classifyCode")
		.append(" left join std_proddruginfo d on d.prod_id=a.prod_id")
		.append(" left join std_drugqualityspec e on e.qualityspec_id=d.qualityspec_id")
		.append(" left join std_compinfo f on f.comp_id=d.prod_comp_id")
		.append(" left join dic_area g on g.area_id=f.area_id")
		.append(" left join dic_drugform h on h.form_id=e.form")
		.append(" left join dic_drugspec i on i.spec_id=e.spec")
		.append(" LEFT JOIN dic_packunit j on j.packunit_id=d.unit")
		.append(" left join dic_drugmaterial k on k.material_id=d.material_id")
		.append(" where a.status=1 and b.status=1 and d.status=1 and f.status=1 and e.status=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("classifyCode", Constants.PROJ_CAT);
		if (StringUtils.isNotBlank(map.get("projId"))){
			sql.append(" and a.proj_id=:projId");
			params.put("projId", map.get("projId"));
		}
		if (StringUtils.isNotBlank(map.get("drugCode"))){
			sql.append(" and d.drug_code=:drugCode");
			params.put("drugCode", map.get("drugCode"));
		}
		if (StringUtils.isNotBlank(map.get("qualityspecName"))){
			sql.append(" and (e.qualityspec_name like :qualityspecName or e.qualityspec_name_spel like :qualityspecNameSpel)");
			params.put("qualityspecName", "%"+map.get("qualityspecName").trim()+"%");
			params.put("qualityspecNameSpel", "%"+map.get("qualityspecName").trim().toUpperCase()+"%");
		}
		if (StringUtils.isNotBlank(map.get("compName"))){
			sql.append(" and (f.comp_name like :compName or f.comp_spel_code like :compSpelCode)");
			params.put("compName", "%"+map.get("compName").trim()+"%");
			params.put("compSpelCode", "%"+map.get("compName").trim().toUpperCase()+"%");
		}
		if (StringUtils.isNotBlank(map.get("projCat"))){
			sql.append(" and b.proj_cat=:projCat");
			params.put("projCat", map.get("projCat"));
		}
		if (StringUtils.isNotBlank(map.get("auditStatus"))){
			sql.append(" and a.audit_status=:auditStatus");
			params.put("auditStatus", map.get("auditStatus"));
		}
		if (StringUtils.isNotBlank(map.get("complainStatus"))){
			sql.append(" and a.complain_status=:complainStatus");
			params.put("complainStatus", map.get("complainStatus"));
		}
		if (StringUtils.isNotBlank(map.get("auditType"))){
			sql.append(" and a.complain_status is not null");
		}
		page.setRows(dao.getSqlMapList(sql.toString(), params)); 
		return page;
	}
	/**
	 * 
	 *@category 获取已申报药品资质的药品
	 *@author 邱磊
	 *@date 2015年9月2日 下午4:04:53
	 *@return
	 */
	public Pagination getDrugCompprofileList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select a.proj_proddrug_id as projProddrugId,b.name,d.prod_comp_id as compId,f.comp_code as compCode,f.comp_name as compName")
		.append(",f.org_code as orgCode,g.ar_fullname as areaName,d.drug_code as drugCode,e.qualityspec_name as qualityspecName,h.form_name as formName,i.spec_name as specName")
		.append(",d.factor,j.packunit_name as unit,k.material_name as materialName,a.audit_status as auditStatus,a.complain_status as complainStatus")
		.append(",b.proj_code as projCode,b.proj_id as projId,b.proj_cat as projCat")
		.append(" from bid_projproddrug a")
		.append(" left join bid_project b on a.proj_id=b.proj_id")
		.append(" left join dic_sysdic c on c.dic_code=b.proj_cat and c.classify_code=:classifyCode")
		.append(" left join std_proddruginfo d on d.prod_id=a.prod_id")
		.append(" left join std_drugqualityspec e on e.qualityspec_id=d.qualityspec_id")
		.append(" left join std_compinfo f on f.comp_id=d.prod_comp_id")
		.append(" left join dic_area g on g.area_id=f.area_id")
		.append(" left join dic_drugform h on h.form_id=e.form")
		.append(" left join dic_drugspec i on i.spec_id=e.spec")
		.append(" LEFT JOIN dic_packunit j on j.packunit_id=d.unit")
		.append(" left join dic_drugmaterial k on k.material_id=d.material_id")
		.append(" where a.status=1 and b.status=1 and d.status=1 and f.status=1 and e.status=1 and (a.audit_status=1 or a.complain_status=1)");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("classifyCode", Constants.PROJ_CAT);
		if (StringUtils.isNotBlank(map.get("projId"))){
			sql.append(" and a.proj_id=:projId");
			params.put("projId", map.get("projId"));
		}
		if (StringUtils.isNotBlank(map.get("drugCode"))){
			sql.append(" and d.drug_code=:drugCode");
			params.put("drugCode", map.get("drugCode"));
		}
		if (StringUtils.isNotBlank(map.get("qualityspecName"))){
			sql.append(" and (e.qualityspec_name like :qualityspecName or e.qualityspec_name_spel like :qualityspecNameSpel)");
			params.put("qualityspecName", "%"+map.get("qualityspecName").trim()+"%");
			params.put("qualityspecNameSpel", "%"+map.get("qualityspecName").trim().toUpperCase()+"%");
		}
		if (StringUtils.isNotBlank(map.get("compName"))){
			sql.append(" and (f.comp_name like :compName or f.comp_spel_code like :compSpelCode)");
			params.put("compName", "%"+map.get("compName").trim()+"%");
			params.put("compSpelCode", "%"+map.get("compName").trim().toUpperCase()+"%");
		}
		if (StringUtils.isNotBlank(map.get("projCat"))){
			sql.append(" and b.proj_cat=:projCat");
			params.put("projCat", map.get("projCat"));
		}
		if (StringUtils.isNotBlank(map.get("auditStatus"))){
			sql.append(" and a.audit_status=:auditStatus");
			params.put("auditStatus", map.get("auditStatus"));
		}
		if (StringUtils.isNotBlank(map.get("complainStatus"))){
			sql.append(" and a.complain_status=:complainStatus");
			params.put("complainStatus", map.get("complainStatus"));
		}
		
		sql.append(" and EXISTS ")
		.append(" (select * from bid_compdrugprofile l where l.proj_proddrug_id=a.proj_proddrug_id");
		if (StringUtils.isNotBlank(map.get("auditType"))){
			sql.append(" and l.complain_status is not null");
		}
		if (StringUtils.isNotBlank(map.get("fStatsu"))){
			sql.append(" and l.audit_status=:fStatsu");
			params.put("fStatsu", map.get("fStatsu"));
		}
		if (StringUtils.isNotBlank(map.get("fCStatsu"))){
			sql.append(" and l.complain_status=:fCStatsu");
			params.put("fCStatsu", map.get("fCStatsu"));//澄清状态0提交1.澄清通过2澄清不通过3未提交
		}
		sql.append(")");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	/**
	 * 
	 *@category 获取报名的生产企业列表
	 *@author 邱磊
	 *@date 2015年9月7日 上午10:55:38
	 *@return
	 */
	public Pagination getJoinProCompDataList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select a.proj_prodcomp_id as projProdcompId,a.status,a.prod_comp_id as compId,b.comp_code as compCode,")
		.append("b.comp_name as compName,b.org_code as orgCode,c.ar_fullname as areaName,b.comp_type as compType,d.comp_reg_name as compRegName")
		.append(" from bid_projprodcompany a")
		.append(" left join std_compinfo b on a.prod_comp_id=b.comp_id")
		.append(" left join dic_area c on c.area_id=b.area_id")
		.append(" left join dic_comptype d on d.comp_reg_id=b.comp_reg_id where a.proj_id=:projId");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("projId", map.get("projId"));
		if (StringUtils.isNotBlank(map.get("compCode"))){
			sql.append(" and b.comp_code=:compCode");
			params.put("compCode", map.get("compCode"));
		}
		if (StringUtils.isNotBlank(map.get("compName"))){
			sql.append(" and (b.comp_name like :compName or b.comp_spel_code like :compSpelCode)");
			params.put("compName", "%"+map.get("compName").trim()+"%");
			params.put("compSpelCode", "%"+map.get("compName").trim().toUpperCase()+"%");
		}
		if (StringUtils.isNotBlank(map.get("area3"))){
			sql.append(" and b.area_id=:areaId");
			params.put("areaId", map.get("area3"));
		}
		else if (StringUtils.isNotBlank(map.get("area2"))){
			sql.append(" and c.father_id=:fatherId");
			params.put("fatherId", map.get("area2"));
		}
		else if (StringUtils.isNotBlank(map.get("area1"))){
			sql.append(" and b.area_id like :province");
			String province = map.get("area1").trim();
			params.put("province",province.substring(0,2)+"%");
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	/**
	 * 
	 *@category 获取中标药品数据列表
	 *@author 邱磊
	 *@date 2015年9月7日 下午1:50:50
	 *@return
	 */
	public Pagination getBindDrugsDataList(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select a.proj_proddrug_id as projProddrugId,d.prod_comp_id as compId,f.comp_code as compCode,f.comp_name as compName")
		.append(",f.org_code as orgCode,g.ar_fullname as areaName,d.drug_code as drugCode,e.qualityspec_name as qualityspecName,h.form_name as formName,i.spec_name as specName")
		.append(",d.factor,j.packunit_name as unit,k.material_name as materialName,a.audit_status as auditStatus,a.complain_status as complainStatus")
		.append(" from bid_projproddrug a")
		.append(" left join std_proddruginfo d on d.prod_id=a.prod_id")
		.append(" left join std_drugqualityspec e on e.qualityspec_id=d.qualityspec_id")
		.append(" left join std_compinfo f on f.comp_id=d.prod_comp_id")
		.append("  left join dic_area g on g.area_id=f.area_id")
		.append(" left join dic_drugform h on h.form_id=e.form")
		.append("  left join dic_drugspec i on i.spec_id=e.spec")
		.append(" LEFT JOIN dic_packunit j on j.packunit_id=d.unit")
		.append("  left join dic_drugmaterial k on k.material_id=d.material_id")
		.append(" where a.status=1 and d.status=1 and f.status=1 and e.status=1")
		.append(" and a.proj_id=:projId and is_bidding=1");
		Map<String, Object> params = new HashMap<String, Object>();
		Map<String, String> map = page.getConditions();
		params.put("projId", map.get("projId"));
		if (StringUtils.isNotBlank(map.get("drugCode"))){
			sql.append(" and d.drug_code=:drugCode");
			params.put("drugCode", map.get("drugCode"));
		}
		if (StringUtils.isNotBlank(map.get("qualityspecName"))){
			sql.append(" and (e.qualityspec_name like :qualityspecName or e.qualityspec_name_spel like :qualityspecNameSpel)");
			params.put("qualityspecName", "%"+map.get("qualityspecName").trim()+"%");
			params.put("qualityspecNameSpel", "%"+map.get("qualityspecName").trim().toUpperCase()+"%");
		}
		if (StringUtils.isNotBlank(map.get("compName"))){
			sql.append(" and (f.comp_name like :compName or f.comp_spel_code like :compSpelCode)");
			params.put("compName", "%"+map.get("compName").trim()+"%");
			params.put("compSpelCode", "%"+map.get("compName").trim().toUpperCase()+"%");
		}
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}

	/**
	 * 
	 *@category 获取投标药品数
	 *@author 应晓川
	 *@date 2015年9月14日20:00:46
	 *@return
	 */
	@Override
	public Pagination getProjDrugList(Pagination page) {
		StringBuffer sql = new StringBuffer()
		 .append(" select a.proj_proddrug_id as projProddrugId, ")
		  .append("       b.name, ")
		  .append("       d.prod_comp_id as compId, ")
		  .append("       f.comp_code as compCode, ")
		  .append("       f.comp_name as compName, ")
		  .append("       f.org_code as orgCode, ")
		  .append("       g.ar_fullname as areaName, ")
		  .append("       d.drug_code as drugCode, ")
		  .append("       e.qualityspec_name as qualityspecName, ")
		  .append("       h.form_name as formName, ")
		  .append("       i.spec_name as specName, ")
		  .append("       d.factor, ")
		  .append("       j.packunit_name as unit, ")
		  .append("       k.material_name as materialName, ")
		  .append("       a.audit_status as auditStatus, ")
		  .append("       a.complain_status as complainStatus, ")
		  .append("       b.proj_cat as projCat, ")
		  .append("       b.proj_code as projCode, ")
		  .append("       b.proj_id as projId  ")
		  .append("   from ")
		  .append("      bid_projproddrug a  ")
		  .append("   left join ")
		  .append("       bid_project b ")
		  .append("           on a.proj_id=b.proj_id  ")
		  .append("            ")
		  .append("   left join ")
		  .append("       dic_sysdic c ")
		  .append("           on c.dic_code=b.proj_cat  ")
		  .append("           and c.classify_code=116 ")
		  .append("   left join ")
		  .append("       std_proddruginfo d  ")
		  .append("           on d.prod_id=a.prod_id  ")
		  .append("   left join ")
		  .append("       std_drugqualityspec e  ")
		  .append("           on e.qualityspec_id=d.qualityspec_id  ")
		  .append("   left join ")
		  .append("       std_compinfo f  ")
		  .append("           on f.comp_id=d.prod_comp_id  ")
		  .append("   left join ")
		  .append("       dic_area g  ")
		  .append("           on g.area_id=f.area_id  ")
		  .append("   left join ")
		  .append("       dic_drugform h  ")
		  .append("           on h.form_id=e.form  ")
		  .append("   left join ")
		  .append("       dic_drugspec i  ")
		  .append("           on i.spec_id=e.spec  ")
		  .append("   LEFT JOIN ")
		  .append("       dic_packunit j  ")
		  .append("           on j.packunit_id=d.unit  ")
		  .append("   left join ")
		  .append("       dic_drugmaterial k  ")
		  .append("           on k.material_id=d.material_id  ")
		  .append("   where ")
		  .append("       a.status=1  ")
		  .append("       and b.status=1  ")
		  .append("       and a.proj_id=:projId ");
		String drugCode = page.getConditions().get("drugCode");
		String qualityspecName = page.getConditions().get("qualityspecName");
			
		if( StringUtils.isNotBlank(drugCode)){
			 sql.append(" and d.drug_code=:drugCode  ");
		}
		if( StringUtils.isNotBlank(qualityspecName)){
			 sql.append(" and e.qualityspec_name=:qualityspecName  ");
		}
		  return dao.getSqlPageMapList(sql.toString(), page.getConditions(), page);
	}
	
	/**
	 * @category 查询不重复的项目
	 * @author 韩守松
	 * @date   2015年9月15日
	 * @param  @param page
	 * @param  @return
	 */
	public Pagination getDataProjList(Pagination page) {
		StringBuffer sql = new StringBuffer()
				.append("select a.proj_id as projId,a.name,a.proj_cat as projCat,a.status,DATE_FORMAT(a.create_datetime,'%Y-%m-%d %T') as createDatetime,")
				.append("DATE_FORMAT(a.starttime,'%Y-%m-%d') as starttime,DATE_FORMAT(a.endtime,'%Y-%m-%d') as endtime,a.proj_intro as projIntro,")
				.append("a.hospCount,a.drugCount,a.delCompCount,a.proCompCount,a.expertCount,b.zb_status as zbStatus,a.biddingDrugCount,a.projProddrugCount from view_bidproject a left join view_bidprojectstatus b on a.proj_id=b.proj_id where 1=1");
		Map<String, String> conditions = page.getConditions();
		Map<String, Object> params = new HashMap<String, Object>();
		if (null != conditions && conditions.size() > 0) {
			if (null != conditions.get("projCode")
					&& !"".equals(conditions.get("projCode").trim())) {
				sql.append(" and a.proj_code=:projCode");
				params.put("projCode", conditions.get("projCode").trim());
			}
			if (null != conditions.get("projId")
					&& !"".equals(conditions.get("projId").trim())) {
				sql.append(" and a.proj_id not in (:projIds) ");
				List<String> list = new ArrayList<String>();
				String[] strId = conditions.get("projId").trim().split(",");
				for(int i=0;i<strId.length;i++){
					list.add(strId[i]);
				}
				params.put("projIds", list);
			}
			if (null != conditions.get("name")
					&& !"".equals(conditions.get("name").trim())) {
				sql.append(" and a.name like :name");
				params.put("name", "%" + conditions.get("name").trim() + "%");
			}
			if (null != conditions.get("status")
					&& !"".equals(conditions.get("status").trim())) {
				sql.append(" and a.status=:status");
				params.put("status", conditions.get("status").trim());
			}
			if (null != conditions.get("zbStatus")
					&& !"".equals(conditions.get("zbStatus").trim())) {
				sql.append(" and b.zb_status=:zbStatus");
				params.put("zbStatus", conditions.get("zbStatus").trim());
			}
			if (null != conditions.get("projCat")
					&& !"".equals(conditions.get("projCat").trim())) {
				sql.append(" and a.proj_cat=:projCat");
				params.put("projCat", conditions.get("projCat").trim());
			}
		}
		sql.append(" order by a.status desc, a.create_datetime desc ");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}

	/**
	 *@category 获取项目切换数据
	 *@author 应晓川
	 *@date 2015年9月15日10:42:53
	 *@return
	 */
	@Override
	public Pagination getChangeBidProjectList(Pagination page) {
		StringBuffer sql = new StringBuffer()
		.append(" select bp.proj_id projId, ")
		.append(" bp.name name, ")
		.append(" bp.proj_intro projIntro, ")
		.append(" bp.starttime starttime, ")
		.append(" bp.endtime endtime, ")
		.append(" bp.status, ")
		.append(" bpd.cur_status curStatus, ")
		.append(" su.default_proj_id defaultProjId ")
		.append(" from bid_project bp left join  bid_project_details bpd on bp.proj_id = bpd.proj_id  ")
		.append(" left join sys_user su on su.default_proj_id = bp.proj_id AND  su.id =:id ")
		.append(" where 1=1 ");
		
		String projId = page.getConditions().get("projId");
		String status = page.getConditions().get("status");
		if (StringUtils.isNotBlank(projId) ) {
			sql.append(" and bp.proj_id = :projId ");
		}
		
		if (StringUtils.isNotBlank(status) ) {
			sql.append(" and bp.status = :status ");
		}
		sql.append(" order by bp.starttime desc ");
		List<?> list =  dao.getSqlMapList(sql.toString(),page.getConditions());
		page.setRows(list);
		return page;
	}
	
	/**
	 * 
	 * @category 根据id获取药品数
	 * @author wangbing
	 * @date 2015年6月11日 上午10:33:20
	 * @param page
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Map<String,String> getDrugCountById(String id) {
		StringBuffer sql = new StringBuffer()
				.append("select a.proj_id as projId,a.name as projName,a.drugCount as drugCount from view_bidproject a left join view_bidprojectstatus b on a.proj_id=b.proj_id where a.proj_id=:projId ");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("projId", id);
		Map<String,String> map = (Map<String, String>) dao.getSqlMapUniqueResult(sql.toString(), params);
		return map;
	}

	/**
	 * @category 获取项目已添加的数量和即将添加的数量
	 * @author 应晓川
	 * @date   2015年9月29日10:50:18
	 * @param  @return
	 */
	@Override
	public Pagination getDrugCount(Pagination page) {
		String projId = page.getConditions().get("projId");
		String drugcatalogId = page.getConditions().get("drugcatalogId");
		//已添加的数量
		String didCount = " select count(*) from bid_qualityspec a left join bid_drugcatas b on a.drugcatas_id=b.drugcatalog_id  and b.qualityspec_id=a.qualityspec_id and b.status=1 where a.proj_id=:projId ";
		//即将添加的数量
		String doingCount = "select count(*) from bid_drugcatas a  left join ( select qualityspec_id from bid_qualityspec where proj_id=:projId ) b on b.qualityspec_id=a.qualityspec_id where a.drugcatalog_id=:drugcatalogId and  b.qualityspec_id is  null  and a.status=1 ";
		
		Query didQuery = getSession().createSQLQuery(didCount);
		Query doingQuery = getSession().createSQLQuery(doingCount);
		
		if(StringUtils.isNotBlank(projId)){
			didQuery.setParameter("projId", projId);
			doingQuery.setParameter("projId", projId);
		}
		if(StringUtils.isNotBlank(drugcatalogId)){
			doingQuery.setParameter("drugcatalogId", drugcatalogId);	
		}
		BigInteger didRecords = (BigInteger) didQuery.uniqueResult();
		BigInteger doingRecords = (BigInteger) doingQuery.uniqueResult();
		List<Integer> list = new ArrayList<Integer>();
		list.add(didRecords.intValue());
		list.add(doingRecords.intValue());
		page.setRows(list);
		return page;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Object> getSelectProjList() {
		String sql = " select f.name as name, a.proj_id as projId from bid_projcompprofile a join bid_project f on f.proj_id=a.proj_id  where a.status=1 group by f.proj_id ";
		Query query = getSession().createSQLQuery(sql.toString());
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		return query.list().size()>0?query.list():null;
	}

	@SuppressWarnings("unchecked")
	@Override
	public BidProject getBidProjectAndTimeById(String projId) throws ParseException {
		StringBuffer hql = new StringBuffer();
		hql.append("select  bp.proj_id projId,bp.proj_code projCode,bp.name,bp.proj_intro projIntro,DATE_FORMAT(bp.starttime,'%Y-%m-%d') starttime, ");
		hql.append("DATE_FORMAT(bp.endtime,'%Y-%m-%d') endtime,bp.proj_cat projCat,bp.remark,case bp.status when 1 then '1' else '0' end status  ,DATE_FORMAT(bp.create_datetime,'%Y-%m-%d') createDatetime, ");
		hql.append("bp.create_user createUser,DATE_FORMAT(bp.upd_datetime,'%Y-%m-%d %H:%i:%S') updDatetime,bp.upd_user updUser,DATE_FORMAT(bpd.proj_starttime,'%Y-%m-%d') projStarttime,DATE_FORMAT(bpd.proj_endtime,'%Y-%m-%d') projEndtime  ");
		hql.append("from bid_project bp ");
		hql.append("left join bid_project_details bpd on bp.proj_id = bpd.proj_id ");
		hql.append("where bp.proj_id = :projId ");
		SQLQuery query = getSession().createSQLQuery(hql.toString());
		query.setString("projId", projId);
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		
		List<Object> list = query.list();
		Map<String,String> map = new HashMap<String, String>();
		map = (Map<String, String>) list.get(0);
		BidProject bidProject = new BidProject();
		bidProject.setProjId(map.get("projId"));
		bidProject.setProjCode(map.get("projCode"));
		bidProject.setName(map.get("name"));
		bidProject.setProjIntro(map.get("projIntro"));
		if(StringUtils.isNotBlank(map.get("starttime"))){
			bidProject.setStarttime(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("starttime")));
		}
		
		if(StringUtils.isNotBlank(map.get("endtime"))){
			bidProject.setEndtime(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("endtime")));
		}
		
		bidProject.setRemark(map.get("remark"));
		bidProject.setStatus(Integer.valueOf(map.get("status")));
		if(StringUtils.isNotBlank(map.get("createDatetime"))){
			bidProject.setCreateDatetime(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("createDatetime")));
		}
		
		bidProject.setCreateUser(map.get("createUser"));
		if(StringUtils.isNotBlank(map.get("updDatetime"))){
			bidProject.setUpdDatetime(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("updDatetime")));
		}
		bidProject.setUpdUser(map.get("updUser"));
		if(StringUtils.isNotBlank(map.get("projStarttime"))){
			bidProject.setProjStartTime(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("projStarttime")));
		}
		if(StringUtils.isNotBlank(map.get("projEndtime"))){
			bidProject.setProjEndTime(new SimpleDateFormat("yyyy-MM-dd").parse(map.get("projEndtime")));
		}
		return bidProject;
		
	}
	
	/**
	 * @category 分院采购情况查看  获取项目列表
	 * @author wangbing
	 * @date   2015年7月15日
	 * @param  @return
	 */
	@Override
	public Pagination getChildHospProjectList(Pagination page){
		String name = page.getConditions().get("name");
		String status = page.getConditions().get("status");
		HospInfo hospInfo = (HospInfo) page.getForm();
		String hospCode = hospInfo.getHospCode();
		StringBuffer sql = new StringBuffer()
		.append("	SELECT a.proj_id projId,b.name projName, ")
		.append("	b.proj_cat projCat,b.status status, ")
		.append("	b.plan_start_datetime starttime,b.proj_code projCode, ")
		.append("	b.plan_end_datetime endtime ")
		.append("	FROM  bid_hospplan a  ")
		.append("	LEFT JOIN bid_project b ON b.proj_id = a.proj_id ")
		.append("	LEFT JOIN std_hospinfo c ON c.hosp_code = a.hosp_code ")
		.append("	WHERE c.father_hosp_code = :hospCode ") ;
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("hospCode", hospCode);
		if(StringUtils.isNotBlank(name)){
			sql.append(" and b.name like :name ");
			params.put("name", "%"+name+"%");
		}
		if(StringUtils.isNotBlank(status)){
			sql.append(" and b.status = :status ");
			params.put("status", status);
		}
		sql.append("	GROUP BY a.proj_id ");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	
	/**
	 * @category 分院采购情况查看  获取药品列表
	 * @author wangbing
	 * @date   2015年7月15日
	 * @param  @return
	 */
	@Override
	public Pagination getChildHospDrugList(Pagination page){
		String drugCode = page.getConditions().get("drugCode");
		String drugName = page.getConditions().get("drugName");
		String compName = page.getConditions().get("compName");
		String projId = page.getConditions().get("projId");
		HospInfo hospInfo = (HospInfo) page.getForm();
		String hospId = hospInfo.getHospCode();
		StringBuffer sql = new StringBuffer()
		.append("	SELECT a.proj_id projId,a.drug_code drugId,b.drug_code drugCode,COUNT(a.hosp_code) hospCount,")
		.append("	b.factor factor,b.unit_name unit,b.material_name materialName,b.comp_name compName,")
		.append("	d.qualityspec_name drugName,d.form_name formName,d.spec_name specName,b.comp_code compId")
		.append("	FROM bid_hospplan a ")
		.append("	LEFT JOIN std_proddruginfo b ON b.drug_code = a.drug_code")  
		.append("	LEFT JOIN std_drugqualityspec d ON d.qualityspec_id = b.qualityspec_id")
		.append("	LEFT JOIN std_hospinfo c ON c.hosp_code = a.hosp_code ")
		.append("	WHERE c.father_hosp_code = :hospId AND a.proj_id = :projId ");
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("hospId", hospId);
		params.put("projId", projId);
		if(StringUtils.isNotBlank(drugCode)){
			sql.append(" and b.drug_code = :drugCode ");
			params.put("drugCode", drugCode);
		}
		if(StringUtils.isNotBlank(drugName)){
			sql.append(" and (d.qualityspec_name like :drugName or d.qualityspec_name_spel like :drugName) ");
			params.put("drugName", "%"+drugName+"%");
		}
		if(StringUtils.isNotBlank(compName)){
			sql.append(" and (b.comp_name like :compName or b.comp_name_spel like :compName) ");
			params.put("compName", "%"+compName+"%");
		}
		sql.append("	GROUP BY a.drug_code ");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	
	/**
	 * @category 分院采购情况查看  获取分院列表
	 * @author wangbing
	 * @date   2015年7月15日
	 * @param  @return
	 */
	@Override
	public Pagination getChildHospList(Pagination page){
		String hospCode = page.getConditions().get("hospCode");
		String hospName = page.getConditions().get("hospName");
		String hospClassify = page.getConditions().get("hospClassify");
		String areaId = page.getConditions().get("areaId");
		String projId = page.getConditions().get("projId");
		HospInfo hospInfo = (HospInfo) page.getForm();
		String hospCode1 = hospInfo.getHospCode();
		StringBuffer sql = new StringBuffer()
		.append("	SELECT b.hosp_name hospName,a.proj_id projId,b.hosp_code hospId,")
		.append("	b.hosp_code hospCode,c.ar_fullname arFullName,")
		.append("	d.dic_name hospClassifyName,e.hosp_type hospType,")
		.append("	COUNT(a.drug_code) drugCount")
		.append("	FROM bid_hospplan a")
		.append("	LEFT JOIN std_hospinfo b ON b.hosp_code = a.hosp_code") 
		.append("	LEFT JOIN dic_area c ON c.area_id = b.area_id")
		.append("	LEFT JOIN dic_sysdic d ON d.dic_code = b.hosp_classify")
		.append("	LEFT JOIN dic_hosptype e ON e.hosp_type_id = b.hosp_type_id") 
		.append("	WHERE b.father_hosp_code  = :hospCode1")
		.append("	AND proj_id = :projId AND classify_code = '113' ");
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("hospCode1", hospCode1);
		params.put("projId", projId);
		if(StringUtils.isNotBlank(hospCode)){
			sql.append(" and b.drug_code = :hospCode ");
			params.put("hospCode", hospCode);
		}
		if(StringUtils.isNotBlank(hospName)){
			sql.append(" and (b.hosp_name like :hospName or b.hosp_spel_code like :hospName) ");
			params.put("hospName", "%"+hospName+"%");
		}
		if(StringUtils.isNotBlank(hospClassify)){
			sql.append(" and b.hosp_classify = :hospClassify  ");
			params.put("hospClassify", hospClassify);
		}
		if(StringUtils.isNotBlank(areaId)){
			sql.append(" and b.area_id like :areaId  ");
			params.put("areaId", areaId+"%");
		}
		sql.append("	GROUP BY a.hosp_code ");
		return dao.getSqlPageMapList(sql.toString(), params, page);
	}
	public void addImportData(Map<String, String> data){
		Session session = sessionFactory.openSession();
		StringBuffer sql = new StringBuffer()
		.append("insert into bid_projdrugs_import")
		.append(" select UUID(),a.proj_id,a.name,a.starttime,a.endtime,a.status,")
		.append(" :drugCode,:coumpCode,1,:fileId,SYSDATE(),:userId")
		.append(" from bid_project a ")
		.append(" where a.proj_id=:projId");
		Map<String, Object> params =  new HashMap<String, Object>();
		params.put("drugCode", data.get("drug_code"));
		params.put("coumpCode", data.get("comp_code"));
		params.put("userId", data.get("user"));
		params.put("projId", data.get("proj_id"));
		params.put("fileId", data.get("file_id"));
		Query query = session.createSQLQuery(sql.toString());
		if (params != null) {
			Iterator<?> list = params.entrySet().iterator();
			while (list.hasNext()) {
				Map.Entry<String, ?> entry = (Map.Entry<String, ?>) list.next();
				query.setParameter((String) entry.getKey(), entry.getValue());
			}
		}
		query.executeUpdate();
		session.clear();
		session.close();
	}
	public List<?> getHaveImportDrug(String projId, String drugCode, String compCode, String fileId){
		Session session = sessionFactory.openSession();
		StringBuffer sql = new StringBuffer()
		.append("select a.proj_drug_id from bid_projdrugs a where a.proj_id = :projId and a.drug_code = :drugCode and a.comp_code = :compCode");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("projId", projId);
		params.put("drugCode", drugCode);
		params.put("compCode", compCode);
		Query query = session.createSQLQuery(sql.toString()).setCacheable(true);
		if (params != null) {
			Iterator<?> list = params.entrySet().iterator();
			while (list.hasNext()) {
				Map.Entry<String, ?> entry = (Map.Entry<String, ?>) list.next();
				query.setParameter((String) entry.getKey(), entry.getValue());
			}
		}
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		List<Map<String, Object>> list = query.list();
		session.clear();
		session.close();
		return list;
	}
	public List<?> getWaitImportDrug(String projId, String drugCode, String compCode, String fileId){
		Session session = sessionFactory.openSession();
		StringBuffer sql = new StringBuffer()
		.append(" select b.proj_drug_id from bid_projdrugs_import b where b.proj_id = :projId and b.drug_code = :drugCode and b.comp_code = :compCode and b.file_id = :fileId");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("projId", projId);
		params.put("drugCode", drugCode);
		params.put("compCode", compCode);
		params.put("fileId", fileId);
		Query query = session.createSQLQuery(sql.toString()).setCacheable(true);
		if (params != null) {
			Iterator<?> list = params.entrySet().iterator();
			while (list.hasNext()) {
				Map.Entry<String, ?> entry = (Map.Entry<String, ?>) list.next();
				query.setParameter((String) entry.getKey(), entry.getValue());
			}
		}
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		List<Map<String, Object>> list = query.list();
		session.clear();
		session.close();
		return list;
	}
	/**
	 * 
	 *@category 获取预览列表
	 *@author 邱磊
	 *@date 2015年11月12日 上午8:32:59
	 *@param
	 */
	public Pagination getImportDrugView(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select c.drug_code as drugCode,d.qualityspec_name as drugName,d.form_name as formName,d.spec_name as specName,")
		.append("c.factor,c.unit_name as unitName,c.material_name as materialName,c.comp_name as compName,c.comp_code as compCode ")
		.append(" from bid_projdrugs_import a ")
		.append(" left join bid_project b on a.proj_id=b.proj_id")
		.append(" left join std_proddruginfo c on a.drug_code = c.drug_code")
		.append(" left join std_drugqualityspec d on c.qualityspec_id=d.qualityspec_id")
		.append(" where a.file_id=:fileId ");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("fileId", page.getConditions().get("fileId"));
		if (StringUtils.isNotBlank(page.getConditions().get("drugName"))){
			sql.append(" and d.qualityspec_name like :drugName");
			params.put("drugName", "%" + page.getConditions().get("drugName") + "%");
		}
		if (StringUtils.isNotBlank(page.getConditions().get("compName"))){
			sql.append(" and c.comp_name like :compName");
			params.put("compName", "%" + page.getConditions().get("compName") + "%");
		} 
		List<?> list = dao.getSqlMapList(sql.toString(), params);
		page.setRows(list);
		return page;
	}
	@Autowired
	private SysImportFileInfoManager sfmanager;
	public int importDrug(String fileId){
		Session session = sessionFactory.openSession();
		StringBuffer sql = new StringBuffer()
		.append("insert into bid_projdrugs select a.proj_drug_id,a.proj_id,a.proj_name,a.proj_starttime,a.proj_endtime,a.proj_status,a.drug_code,")
		.append(" a.comp_code,a.status,a.upd_datetime,a.upd_user from bid_projdrugs_import a where a.file_id=:fileId")
		.append(" and not exists")
		.append(" (select * from bid_projdrugs b where a.proj_id=b.proj_id and a.drug_code=b.drug_code)");
		Query query = session.createSQLQuery(sql.toString());
		query.setParameter("fileId", fileId);
		int flag = query.executeUpdate();
		session.clear();
		session.close();
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("fileId", fileId);
		StringBuffer logsql = new StringBuffer()
		.append("insert into bid_projdrugs_log select UUID(),a.proj_drug_id,a.proj_id,a.proj_name,a.proj_starttime,a.proj_endtime,a.proj_status,a.drug_code,")
		.append(" a.comp_code,a.status,a.upd_datetime,a.upd_user from bid_projdrugs_import a where a.file_id=:fileId")
		.append(" and not exists")
		.append(" (select * from bid_projdrugs b where a.proj_id=b.proj_id and a.drug_code=b.drug_code)");
		dao.executeSql(logsql.toString(), params);
		deleteImportDrug(fileId);
		return flag;
	}
	
	public void deleteImportDrug(String fileId){
		String sql = "DELETE from bid_projdrugs_import where file_id=:fileId ";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("fileId", fileId);
		dao.executeSql(sql, params);
	}
	
	
	/**
	 * 获取项目已添加医疗机构
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Pagination getAddedBidProjectHospList(Pagination page) {
		String projId = page.getConditions().get("projId");
		String hospName = page.getConditions().get("hospName");
		String hospClassify = page.getConditions().get("hospClassify");
		String hospClassifys = page.getConditions().get("hospClassifys");
		String hospType = page.getConditions().get("hospType");
		String hospCode = page.getConditions().get("hospCode");
		String areaId = page.getConditions().get("areaId");
		String status = page.getConditions().get("status");

		StringBuffer hql = new StringBuffer();
		hql.append(" select sh.hosp_id hospId,sh.hosp_code hospCode,sh.area_id areaId,sh.hosp_name hospName,");
		hql.append(" da.ar_fullname arfullname,sh.hosp_classify hospClassify,dh.hosp_type hospType,sh.hosp_level_id hospLevelId,");
		hql.append(" sh.org_code orgCode,b.status status, b.proj_hosp_id projHospId ");
		hql.append(" from bid_projhospital b ");
		hql.append(" join std_hospinfo sh on sh.hosp_code = b.hosp_code  ");
		hql.append(" left join dic_area da on  sh.area_id = da.area_id ");
		hql.append(" left join dic_hosptype dh on  sh.hosp_type_id = dh.hosp_type_id ");
		hql.append(" where 1=1 ");
		if (StringUtils.isNotEmpty(projId)) {
			hql.append(" and b.proj_id = :projId");
		}
		if (StringUtils.isNotEmpty(hospName)) {
			if (PinYin.isPinYin(hospName.trim())) {
				hql.append(" and sh.hosp_spel_code like :hospName ");
			} else {
				hql.append(" and sh.hosp_name like :hospName ");
			}
		}
		if (StringUtils.isNotEmpty(hospClassify)) {
			hql.append(" and sh.hosp_classify=:hospClassify");
		}
		if (StringUtils.isNotEmpty(hospClassifys)) {
			hql.append(" and sh.hosp_classify=:hospClassifys");
		}
		if (StringUtils.isNotEmpty(hospType)) {
			hql.append(" and sh.hosp_level_id=:hospType");
		}
		if (StringUtils.isNotEmpty(hospCode)) {
			hql.append(" and sh.hosp_code=:hospCode");
		}
		if (StringUtils.isNotEmpty(areaId)) {
			hql.append(" and sh.area_id like :areaId");
		}
		if (StringUtils.isNotEmpty(status)) {
			hql.append(" and b.status=:status");
		}
		hql.append(" order by sh.hosp_code");
		Query query = getSession().createSQLQuery(hql.toString());

		if (StringUtils.isNotEmpty(projId)) {
			query.setParameter("projId", projId);
		}
		if (StringUtils.isNotEmpty(hospName)) {
			query.setParameter("hospName", "%" + hospName + "%");
		}
		if (StringUtils.isNotEmpty(hospClassify)) {
			query.setInteger("hospClassify", Integer.valueOf(hospClassify));
		}
		if (StringUtils.isNotEmpty(hospClassifys)) {
			query.setInteger("hospClassifys", Integer.valueOf(hospClassifys));
		}
		if (StringUtils.isNotEmpty(hospType)) {
			query.setInteger("hospType", Integer.valueOf(hospType));
		}
		if (StringUtils.isNotEmpty(hospCode)) {

			query.setParameter("hospCode", hospCode);
		}
		if (StringUtils.isNotEmpty(areaId)) {
			query.setParameter("areaId", areaId + "%");
		}
		if (StringUtils.isNotEmpty(status)) {
			query.setParameter("status", status);
		}
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		List<Map> list = query.list();
		if (list.size() > 0) {
			page.setRecords(list.size());
		} else {
			page.setRecords(0);
		}

		query.setFirstResult((page.getPage() - 1) * page.getMaxResults());
		query.setMaxResults(page.getMaxResults());
		list = query.list();
		list = formatHospInfo(list);
		if (list.size() > 0) {
			page.setRows(list);
		} else {
			page.setRows(new ArrayList<HospInfo>());
		}

		page.setTotal(new Long(
				page.getRecords() % page.getMaxResults() == 0 ? page
						.getRecords() / page.getMaxResults() : page
						.getRecords() / page.getMaxResults() + 1).intValue());
		return page;
	}

	/* (non-Javadoc)
	 * @see com.hsnn.medstgmini.pro.project.dao.BidProjectDao#updateHospStatus(com.hsnn.medstgmini.pro.project.model.BidProjhospital, java.lang.Short)
	 */
	@Override
	public boolean updateHospStatus(BidProjhospital bidProjhospital,
			Short status) {
		StringBuffer hql = new StringBuffer();
		hql.append(" update bid_projhospital set status =:status, upd_user =:updUser, upd_datetime =:updDttm where proj_hosp_id =:projHospId");

		Query query = getSession().createSQLQuery(hql.toString());
		query.setShort("status", status);
		query.setParameter("updUser", bidProjhospital.getUpdUser());
		query.setTimestamp("updDttm", bidProjhospital.getUpdDatetime());
		query.setParameter("projHospId", bidProjhospital.getProjHospId());
		query.executeUpdate();

		hql = new StringBuffer();
		hql.append(" insert into bid_projhospital_log (log_id, proj_hosp_id, proj_id, hosp_code, status, upd_datetime, upd_user) ")
				.append(" values(?, ?, ?, ?, ?, ?, ?) ");
		query = getSession().createSQLQuery(hql.toString());
		query.setParameter(0, UUID.randomUUID().toString());
		query.setParameter(1, bidProjhospital.getProjHospId());
		query.setParameter(2, bidProjhospital.getProjId());
		query.setParameter(3, bidProjhospital.getHospCode());
		query.setShort(4, status);
		query.setTimestamp(5, bidProjhospital.getUpdDatetime());
		query.setParameter(6, bidProjhospital.getUpdUser());
		query.executeUpdate();
		return true;
	
	}
	public List<Map<String, Object>> getProjInfoById(String projId){
		String sql = "select * from bid_project where proj_id = :projId";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("projId", projId);
		return (List<Map<String, Object>>) dao.getSqlMapList(sql, params);
	}
	/**
	 * 
		 * 
		 *@category 根据项目ID与品规Id查询采购项目药品
		 *@author 邱磊
		 *@date 2015年11月11日 上午11:13:29
		 *@param 
		 *@return List<?>
	 */
	public List<?> getPorjDrug(String projId,String drugCode){
		Session session = sessionFactory.openSession();
		String sql = "SELECT * from bid_projdrugs a where a.proj_id=:projId and a.drug_code=:drugCode";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("projId", projId);
		params.put("drugCode", drugCode);
		Query query = session.createSQLQuery(sql.toString()).setCacheable(true);
		if (params != null) {
			Iterator<?> list = params.entrySet().iterator();
			while (list.hasNext()) {
				Map.Entry<String, ?> entry = (Map.Entry<String, ?>) list.next();
				query.setParameter((String) entry.getKey(), entry.getValue());
			}
		}
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		List<Map<String, Object>> list = query.list();
		session.clear();
		session.close();
		return list;
	}
	public List<Map<String, Object>> getProjByName(String projectName){
		Session session = sessionFactory.openSession();
		String sql = "select * from bid_project t where t.name = :projNmae";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("projNmae", projectName);
		Query query = session.createSQLQuery(sql.toString()).setCacheable(true);
		if (params != null) {
			Iterator<?> list = params.entrySet().iterator();
			while (list.hasNext()) {
				Map.Entry<String, ?> entry = (Map.Entry<String, ?>) list.next();
				query.setParameter((String) entry.getKey(), entry.getValue());
			}
		}
		query.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
		List<Map<String, Object>> list = query.list();
		session.clear();
		session.close();
		return list;
	}
	public BidProjectDetails getProjDetail(String projId){
		Session session = sessionFactory.openSession();
		BidProjectDetails data = (BidProjectDetails) session.get(BidProjectDetails.class, projId);
		session.clear();
		session.close();
		return data;
	}
	public List<Map<String, Object>> checkReImport(Pagination page){
		StringBuffer sql = new StringBuffer()
		.append("select count(*) as importCount,")
		.append(" sum((select count(*)  from bid_projdrugs b where a.proj_id=b.proj_id and a.drug_code=b.drug_code)) as drugCount ")
		.append(" from bid_projdrugs_import a")
		.append(" where a.file_id = :fileId");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("fileId", page.getConditions().get("fileId"));
		return (List<Map<String, Object>>) dao.getSqlMapList(sql.toString(), params);
	}
	
	/**
	 * @category 保存项目与药品关系表数据
	 * @author 韩守松
	 * @date   2016年1月18日
	 * @param
	 */
	public void saveProjDrug(Map<String,Object> map,BaseGoods goods){
		StringBuffer hql = new StringBuffer();
		hql.append("insert into bid_projdrugs( ");
		hql.append(" proj_drug_id,proj_id,proj_name,proj_starttime,proj_endtime,proj_status, ");
		hql.append(" drug_code,comp_code,status,upd_datetime,upd_user ");
		hql.append(" ) values( ");
		hql.append(" :proj_drug_id,:proj_id,:proj_name,:proj_starttime,:proj_endtime,:proj_status, ");
		hql.append(" :drug_code,:comp_code,:status,:upd_datetime,:upd_user ");
		hql.append(" ) ");
		SQLQuery query = getSession().createSQLQuery(hql.toString());
		query.setParameter("proj_drug_id", UUID.randomUUID().toString());
		query.setParameter("proj_id",map.get("proj_id") );
		query.setParameter("proj_name",map.get("name") );
		query.setParameter("proj_starttime",map.get("starttime") );
		query.setParameter("proj_endtime",map.get("endtime") );
		query.setParameter("proj_status", map.get("status"));
		query.setParameter("drug_code", goods.getDrugCode());
		query.setParameter("comp_code", goods.getProdCode());
		query.setParameter("status", Status.enabled.getKey());
		query.setParameter("upd_datetime", new Date());
		query.setParameter("upd_user","1");
		query.executeUpdate();
		getSession().flush();
		getSession().clear();
	}
}
